GoodsServer - 副本.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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_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,$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_content'] = $goods_content;
  50. $data['goods_sell_num'] = $goods_sell_num;
  51. $data['goods_postage_id'] = $goods_postage_id;
  52. $data['goods_category_id'] = $goods_category_id;
  53. $data['goods_status'] = $goods_status;
  54. $data['goods_weight'] = $goods_weight;
  55. $data['goods_sort'] = $goods_sort;
  56. $data['goods_slide'] = implode(',',$goods_slide);
  57. $data['goods_pack_price'] = $goods_pack_price;
  58. $data['goods_attr'] = $food_attr;
  59. $data['goods_varieties'] = $food_varieties;
  60. $data['goods_packaging'] = $food_packaging;
  61. $data['goods_storage'] = $food_storage;
  62. $data['goods_update_time'] = time();
  63. $result = LifeGoods::where($where)->update($data);
  64. if ($result !== false){
  65. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改健康超市商品-编号: ' . $goods_id;
  66. plog('life-goods-update', '悦活-健康超市-修改商品', $msg);
  67. LifeGoods::affairCommit();
  68. return true;
  69. }
  70. throw new \Exception('操作失败!');
  71. }catch (\Exception $exception){
  72. LifeGoods::affairRollback();
  73. throw new \Exception($exception->getMessage(), 500);
  74. }
  75. }
  76. /**
  77. * Notes:删除商品
  78. * @param int $goods_id
  79. * @return int
  80. * User: ZQ
  81. * Date: 2022/9/13
  82. */
  83. public static function delGoods($goods_id,$admin_id)
  84. {
  85. LifeGoods::affairBegin();
  86. try {
  87. $where = [];
  88. $where['goods_id'] = $goods_id;
  89. $data['goods_is_del'] = 1;
  90. $result = LifeGoods::where($where)->update($data);
  91. if (!empty($result)){
  92. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除健康超市商品-编号: ' . $goods_id;
  93. plog('life-goods-delete', '悦活-健康超市-删除商品', $msg);
  94. LifeGoods::affairCommit();
  95. return true;
  96. }else{
  97. return false;
  98. }
  99. }catch (\Exception $exception){
  100. LifeGoods::affairRollback();
  101. throw new \Exception($exception->getMessage(), 500);
  102. }
  103. }
  104. /**
  105. * Notes: 添加商品
  106. * @param string $goods_name
  107. * @param array $goods_rules
  108. * @return int
  109. * User: ZQ
  110. * Date: 2022/9/13
  111. */
  112. public static function insertGoods($goods_name,$goods_img,$goods_category_id,$goods_shop_id,$goods_is_new,$goods_price,$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,$admin_id)
  113. {
  114. LifeGoods::affairBegin();
  115. try {
  116. $data = [];
  117. $data['goods_name'] = $goods_name;
  118. $data['goods_img'] = $goods_img;
  119. $data['goods_shop_id'] = $goods_shop_id;
  120. $data['goods_is_new'] = $goods_is_new;
  121. $data['goods_price'] = $goods_price;
  122. $data['goods_content'] = $goods_content;
  123. $data['goods_sell_num'] = $goods_sell_num;
  124. $data['goods_postage_id'] = $goods_postage_id;
  125. $data['goods_category_id'] = $goods_category_id;
  126. $data['goods_status'] = $goods_status;
  127. $data['goods_weight'] = $goods_weight;
  128. $data['goods_sort'] = $goods_sort;
  129. $data['goods_slide'] = implode(',',$goods_slide);
  130. $data['goods_pack_price'] = $goods_pack_price;
  131. $data['goods_attr'] = $food_attr;
  132. $data['goods_varieties'] = $food_varieties;
  133. $data['goods_packaging'] = $food_packaging;
  134. $data['goods_storage'] = $food_storage;
  135. $data['goods_create_time'] = time();
  136. $result = LifeGoods::insertGetId($data);
  137. if (!empty($result)){
  138. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加健康超市商品-编号: ' . $result;
  139. plog('life-goods-create', '悦活-健康超市-添加商品', $msg);
  140. LifeGoods::affairCommit();
  141. return $result;
  142. }
  143. throw new \Exception('操作失败!');
  144. }catch (\Exception $exception){
  145. LifeGoods::affairRollback();
  146. throw new \Exception($exception->getMessage(), 500);
  147. }
  148. }
  149. /**
  150. * Notes:查询商品
  151. * @param int $goods_id
  152. * @return int
  153. * User: ZQ
  154. * Date: 2022/9/13
  155. */
  156. public static function goodsInfo($goods_id)
  157. {
  158. $where = [];
  159. $where['goods_id'] = $goods_id;
  160. $where['goods_is_del'] = 0;
  161. $result = LifeGoods::where($where)
  162. ->leftJoin('merchant_shop','shop_id','=','life_market_goods.goods_shop_id')
  163. ->leftJoin('category','category_id','=','life_market_goods.goods_category_id')
  164. ->first(['life_market_goods.*','merchant_shop.shop_name','category.category_name']);
  165. if (!empty($result)){
  166. $result['goods_slide'] = explode(',',$result['goods_slide']);
  167. $result['goods_create_time'] = date('Y-m-d H:i:s',$result['goods_create_time']);
  168. if (!empty($result['goods_update_time'])){
  169. $result['goods_update_time'] = date('Y-m-d H:i:s',$result['goods_update_time']);
  170. }
  171. }
  172. return $result;
  173. }
  174. /**
  175. * Notes:修改商品状态
  176. * @param string $goods_name
  177. * @param int $goods_status
  178. * @return int
  179. * User: ZQ
  180. * Date: 2022/9/15
  181. */
  182. public static function updateStatus($goods_id, $goods_status)
  183. {
  184. LifeGoods::affairBegin();
  185. try {
  186. $where = [];
  187. $where['goods_id'] = $goods_id;
  188. $data = [];
  189. $data['goods_status'] = $goods_status;
  190. $result = LifeGoods::where($where)->update($data);
  191. if ($result !== false){
  192. LifeGoods::affairCommit();
  193. return true;
  194. }
  195. throw new \Exception('操作失败!');
  196. }catch (\Exception $exception){
  197. LifeGoods::affairRollback();
  198. throw new \Exception($exception->getMessage(), 500);
  199. }
  200. }
  201. }