GoodsServer.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\LifeGoods;
  4. class GoodsServer
  5. {
  6. /**
  7. * Notes:获取商品列表
  8. * @param string $keywords
  9. * @param int $page
  10. * @param int $limit
  11. * @return array
  12. * User: ZQ
  13. * Date: 2022/9/13
  14. */
  15. public static function getGoodsList(int $page, int $limit, string $keywords)
  16. {
  17. [$list, $count] = LifeGoods::getGoodsList($page, $limit, $keywords);
  18. if (!empty($list)){
  19. foreach ($list as $k => $v){
  20. $list[$k]['goods_slide'] = explode(',',$v['goods_slide']);
  21. $list[$k]['goods_create_time'] = date('Y-m-d H:i:s',$v['goods_create_time']);
  22. if (!empty($v['goods_update_time'])){
  23. $list[$k]['goods_update_time'] = date('Y-m-d H:i:s',$v['goods_update_time']);
  24. }
  25. }
  26. }
  27. return compact('list', 'page', 'limit', 'count');
  28. }
  29. /**
  30. * Notes:修改商品
  31. * @param string $goods_name
  32. * @param int $goods_id
  33. * @return int
  34. * User: ZQ
  35. * Date: 2022/9/3
  36. */
  37. public static function updateGoods($goods_id,$goods_name,$goods_img,$goods_category_id,$goods_shop_id,$goods_is_new,$goods_price,$goods_oldprice,$goods_content,$goods_sell_num,$goods_postage_id,$goods_status,$goods_weight,$goods_sort,$goods_slide,$goods_pack_price,$food_attr,$food_varieties,$food_packaging,$food_storage,$goods_delivery_type,$goods_inventory,$admin_id)
  38. {
  39. LifeGoods::affairBegin();
  40. try {
  41. $where = [];
  42. $where['goods_id'] = $goods_id;
  43. $data = [];
  44. $data['goods_name'] = $goods_name;
  45. $data['goods_img'] = $goods_img;
  46. $data['goods_shop_id'] = $goods_shop_id;
  47. $data['goods_is_new'] = $goods_is_new;
  48. $data['goods_price'] = $goods_price;
  49. $data['goods_oldprice'] = $goods_oldprice;
  50. $data['goods_content'] = $goods_content;
  51. $data['goods_sell_num'] = $goods_sell_num;
  52. $data['goods_postage_id'] = $goods_postage_id;
  53. $data['goods_category_id'] = $goods_category_id;
  54. $data['goods_status'] = $goods_status;
  55. $data['goods_weight'] = $goods_weight;
  56. $data['goods_sort'] = $goods_sort;
  57. $data['goods_slide'] = implode(',',$goods_slide);
  58. $data['goods_pack_price'] = $goods_pack_price;
  59. $data['goods_attr'] = $food_attr;
  60. $data['goods_varieties'] = $food_varieties;
  61. $data['goods_packaging'] = $food_packaging;
  62. $data['goods_storage'] = $food_storage;
  63. $data['goods_delivery_type'] = $goods_delivery_type;
  64. $data['goods_inventory'] = $goods_inventory;
  65. $data['goods_update_time'] = time();
  66. $result = LifeGoods::where($where)->update($data);
  67. if ($result !== false){
  68. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改健康超市商品-编号: ' . $goods_id;
  69. plog('life-goods-update', '悦活-健康超市-修改商品', $msg);
  70. LifeGoods::affairCommit();
  71. return true;
  72. }
  73. throw new \Exception('操作失败!');
  74. }catch (\Exception $exception){
  75. LifeGoods::affairRollback();
  76. throw new \Exception($exception->getMessage(), 500);
  77. }
  78. }
  79. /**
  80. * Notes:删除商品
  81. * @param int $goods_id
  82. * @return int
  83. * User: ZQ
  84. * Date: 2022/9/13
  85. */
  86. public static function delGoods($goods_id,$admin_id)
  87. {
  88. LifeGoods::affairBegin();
  89. try {
  90. $where = [];
  91. $where['goods_id'] = $goods_id;
  92. $data['goods_is_del'] = 1;
  93. $result = LifeGoods::where($where)->update($data);
  94. if (!empty($result)){
  95. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除健康超市商品-编号: ' . $goods_id;
  96. plog('life-goods-delete', '悦活-健康超市-删除商品', $msg);
  97. LifeGoods::affairCommit();
  98. return true;
  99. }else{
  100. return false;
  101. }
  102. }catch (\Exception $exception){
  103. LifeGoods::affairRollback();
  104. throw new \Exception($exception->getMessage(), 500);
  105. }
  106. }
  107. /**
  108. * Notes: 添加商品
  109. * @param string $goods_name
  110. * @param array $goods_rules
  111. * @return int
  112. * User: ZQ
  113. * Date: 2022/9/13
  114. */
  115. public static function insertGoods($goods_name,$goods_img,$goods_category_id,$goods_shop_id,$goods_is_new,$goods_price,$goods_oldprice,$goods_content,$goods_sell_num,$goods_postage_id,$goods_status,$goods_weight,$goods_sort,$goods_slide,$goods_pack_price,$food_attr,$food_varieties,$food_packaging,$food_storage,$goods_delivery_type,$goods_inventory,$admin_id)
  116. {
  117. LifeGoods::affairBegin();
  118. try {
  119. $data = [];
  120. $data['goods_name'] = $goods_name;
  121. $data['goods_img'] = $goods_img;
  122. $data['goods_shop_id'] = $goods_shop_id;
  123. $data['goods_is_new'] = $goods_is_new;
  124. $data['goods_price'] = $goods_price;
  125. $data['goods_oldprice'] = $goods_oldprice;
  126. $data['goods_content'] = $goods_content;
  127. $data['goods_sell_num'] = $goods_sell_num;
  128. $data['goods_postage_id'] = $goods_postage_id;
  129. $data['goods_category_id'] = $goods_category_id;
  130. $data['goods_status'] = $goods_status;
  131. $data['goods_weight'] = $goods_weight;
  132. $data['goods_sort'] = $goods_sort;
  133. $data['goods_slide'] = implode(',',$goods_slide);
  134. $data['goods_pack_price'] = $goods_pack_price;
  135. $data['goods_attr'] = $food_attr;
  136. $data['goods_varieties'] = $food_varieties;
  137. $data['goods_packaging'] = $food_packaging;
  138. $data['goods_storage'] = $food_storage;
  139. $data['goods_delivery_type'] = $goods_delivery_type;
  140. $data['goods_inventory'] = $goods_inventory;
  141. $data['goods_create_time'] = time();
  142. $result = LifeGoods::insertGetId($data);
  143. if (!empty($result)){
  144. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加健康超市商品-编号: ' . $result;
  145. plog('life-goods-create', '悦活-健康超市-添加商品', $msg);
  146. LifeGoods::affairCommit();
  147. return $result;
  148. }
  149. throw new \Exception('操作失败!');
  150. }catch (\Exception $exception){
  151. LifeGoods::affairRollback();
  152. throw new \Exception($exception->getMessage(), 500);
  153. }
  154. }
  155. /**
  156. * Notes:查询商品
  157. * @param int $goods_id
  158. * @return int
  159. * User: ZQ
  160. * Date: 2022/9/13
  161. */
  162. public static function goodsInfo($goods_id)
  163. {
  164. $where = [];
  165. $where['goods_id'] = $goods_id;
  166. $where['goods_is_del'] = 0;
  167. $result = LifeGoods::where($where)
  168. ->leftJoin('merchant_shop','shop_id','=','life_market_goods.goods_shop_id')
  169. ->leftJoin('category','category_id','=','life_market_goods.goods_category_id')
  170. ->first(['life_market_goods.*','merchant_shop.shop_name','category.category_name']);
  171. if (!empty($result)){
  172. $result['goods_slide'] = explode(',',$result['goods_slide']);
  173. $result['goods_create_time'] = date('Y-m-d H:i:s',$result['goods_create_time']);
  174. if (!empty($result['goods_update_time'])){
  175. $result['goods_update_time'] = date('Y-m-d H:i:s',$result['goods_update_time']);
  176. }
  177. }
  178. return $result;
  179. }
  180. /**
  181. * Notes:修改商品状态
  182. * @param string $goods_name
  183. * @param int $goods_status
  184. * @return int
  185. * User: ZQ
  186. * Date: 2022/9/15
  187. */
  188. public static function updateStatus($goods_id, $goods_status)
  189. {
  190. LifeGoods::affairBegin();
  191. try {
  192. $where = [];
  193. $where['goods_id'] = $goods_id;
  194. $data = [];
  195. $data['goods_status'] = $goods_status;
  196. $result = LifeGoods::where($where)->update($data);
  197. if ($result !== false){
  198. LifeGoods::affairCommit();
  199. return true;
  200. }
  201. throw new \Exception('操作失败!');
  202. }catch (\Exception $exception){
  203. LifeGoods::affairRollback();
  204. throw new \Exception($exception->getMessage(), 500);
  205. }
  206. }
  207. }