Card.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\cashier\storeapi\controller;
  13. use app\model\goods\Goods as GoodsModel;
  14. use app\storeapi\controller\BaseStoreApi;
  15. use think\facade\Db;
  16. /**
  17. * 卡项控制器
  18. * Class Activity
  19. * @package addon\shop\storeapi\controller
  20. */
  21. class Card extends BaseStoreApi
  22. {
  23. public function page()
  24. {
  25. $page_index = $this->params[ 'page' ] ?? 1;
  26. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  27. $goods_category = $this->params[ 'category' ] ?? 'all';
  28. $search_text = $this->params[ 'search_text' ] ?? '';
  29. $goods_class = $this->params[ 'goods_class' ] ?? 'all';
  30. $card_type = $this->params[ 'card_type' ] ?? 'all';
  31. $model = new GoodsModel();
  32. $condition = [
  33. [ 'g.site_id', '=', $this->site_id ],
  34. [ 'g.is_delete', '=', 0 ],
  35. [ 'g.goods_state', '=', 1 ],
  36. [ 'g.sale_store', 'like', ['%all%', '%,'.$this->store_id.',%'], 'or' ],
  37. [ '', 'exp', Db::raw("(g.sale_channel = 'all' OR g.sale_channel = 'offline')") ]
  38. ];
  39. if ($goods_class !== 'all') {
  40. $condition[] = [ 'g.goods_class', '=', $goods_class ];
  41. }else{
  42. $condition[] = [ 'g.goods_class', 'in', '1,4,5,6' ];
  43. }
  44. if ($card_type !== 'all') {
  45. $condition[] = [ 'gc.card_type', '=', $card_type ];
  46. }
  47. if ($goods_category != 'all') $condition[] = [ 'g.category_id', 'like', "%,{$goods_category},%" ];
  48. if ($search_text != '') $condition[] = [ 'g.goods_name', 'like', "%{$search_text}%" ];
  49. if(addon_is_exit('store')){
  50. $status = $this->params[ 'status' ] ?? 1;
  51. if($status !== 'all'){
  52. $condition[] = [ 'sg.status', '=', $status ];
  53. }
  54. $field = 'g.goods_id,g.goods_name,g.introduction,g.goods_image,g.goods_state,g.sku_id,g.price,gs.discount_price,g.goods_spec_format,g.is_unify_price,
  55. IFNULL(IF(g.is_unify_price = 1,g.price,sg.price), g.price) as price, IFNULL(IF(g.is_unify_price = 1,gs.discount_price,sg.price), gs.discount_price) as discount_price,
  56. sg.price as store_price,gc.card_type,gc.card_type_name,gc.renew_price,gc.recharge_money,gc.common_num,gc.discount_goods_type,gc.discount,gc.validity_type,gc.validity_day,gc.validity_time';
  57. $join = [
  58. ['goods_sku gs', 'gs.sku_id = g.sku_id', 'left'],
  59. ['store_goods sg', 'g.goods_id=sg.goods_id and sg.store_id='.$this->store_id, 'left'],
  60. ['goods_card gc', 'gc.goods_id = g.goods_id', 'left'],
  61. ];
  62. $stock_store_id = (new \app\model\store\Store())->getStoreStockTypeStoreId(['store_id' => $this->store_id])['data'] ?? 0;
  63. if($stock_store_id == $this->store_id){
  64. $field .= ', IFNULL(sg.stock, 0) as stock';
  65. }else{
  66. $join[] = ['store_goods sg2', 'g.goods_id = sg2.goods_id and sg2.store_id='.$stock_store_id, 'left'];
  67. $field .= ', IFNULL(sg2.stock, 0) as stock';
  68. }
  69. }else{
  70. $field = 'g.goods_id,g.goods_name,g.introduction,g.goods_image,g.goods_state,g.sku_id,g.price,gs.discount_price,g.goods_spec_format,g.is_unify_price,
  71. gc.card_type,gc.card_type_name,gc.renew_price,gc.recharge_money,gc.common_num,gc.discount_goods_type,gc.discount,gc.validity_type,gc.validity_day,gc.validity_time';
  72. $join = [
  73. ['goods_sku gs', 'gs.sku_id = g.sku_id', 'left'],
  74. ['goods_card gc', 'gc.goods_id = g.goods_id', 'left'],
  75. ];
  76. }
  77. $data = $model->getGoodsPageList($condition, $page_index, $page_size, 'g.sort asc,g.create_time desc', $field, 'g', $join);
  78. return $this->response($data);
  79. }
  80. /**
  81. * 商品详情
  82. * @return false|string
  83. */
  84. public function detail()
  85. {
  86. $goods_id = $this->params[ 'goods_id' ] ?? 0;
  87. $goods_model = new GoodsModel();
  88. $field = 'g.goods_id, g.goods_name, g.introduction, g.goods_class_name, g.goods_image, g.goods_state, g.sku_id, g.price, g.unit, g.cost_price, g.category_id, g.brand_name,g.is_unify_price,
  89. sg.stock as store_stock, sg.price as store_price, sg.cost_price as store_cost_price, sg.status as store_status,
  90. gc.card_type,gc.card_type_name,gc.renew_price,gc.recharge_money,gc.common_num,gc.discount_goods_type,gc.discount,gc.validity_type,gc.validity_day,gc.validity_time';
  91. $join = [
  92. ['store_goods sg', 'g.goods_id=sg.goods_id and sg.store_id=' . $this->store_id, 'left'],
  93. ['goods_card gc', 'gc.goods_id = g.goods_id', 'left'],
  94. ];
  95. $goods_info = $goods_model->getGoodsInfo([ [ 'g.goods_id', '=', $goods_id ], [ 'g.site_id', '=', $this->site_id ] ], $field, 'g', $join)[ 'data' ];
  96. if (empty($goods_info)) return $this->response($goods_model->error(null, '商品信息缺失'));
  97. //查询商品规格
  98. $sku_filed = 'sku.sku_id,sku.sku_name,sku.sku_no,sku.price,sku.discount_price,sku.cost_price,sku.sku_image,sku.sku_images,sku.spec_name,
  99. sgs.price as store_price, sgs.cost_price as store_cost_price, sgs.status as store_status';
  100. $join = [
  101. ['store_goods_sku sgs', 'sku.sku_id=sgs.sku_id and sgs.store_id='.$this->store_id, 'left']
  102. ];
  103. $goods_info[ 'sku_list' ] = $goods_model->getGoodsSkuList([ [ 'sku.goods_id', '=', $goods_id ], [ 'sku.site_id', '=', $this->site_id ] ], $sku_filed, 'sku.sku_id asc', 0, 'sku', $join)[ 'data' ];
  104. return $this->response($goods_model->success($goods_info));
  105. }
  106. }