FoodServer.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\LifeFood;
  4. class FoodServer
  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/10/17
  14. */
  15. public static function getFoodList(int $page, int $limit, string $keywords)
  16. {
  17. [$list, $count] = LifeFood::getFoodList($page, $limit, $keywords);
  18. if (!empty($list)){
  19. foreach ($list as $k => $v){
  20. $list[$k]['food_silde'] = explode(',',$v['food_silde']);
  21. $list[$k]['food_materials'] = json_decode($v['food_materials'],true);
  22. $list[$k]['food_condiment'] = json_decode($v['food_condiment'],true);
  23. $list[$k]['food_create_time'] = date('Y-m-d H:i:s',$v['food_create_time']);
  24. if (!empty($v['food_update_time'])){
  25. $list[$k]['food_update_time'] = date('Y-m-d H:i:s',$v['food_update_time']);
  26. }
  27. }
  28. }
  29. return compact('list', 'page', 'limit', 'count');
  30. }
  31. /**
  32. * Notes:获取分类下的美食列表
  33. * @return int
  34. * User: ZQ
  35. * Date: 2022/10/17
  36. */
  37. public static function getFoodAll($food_category_id)
  38. {
  39. $where = [];
  40. $where['food_is_del'] = 0;
  41. $where['food_status'] = 0;
  42. $where['food_type'] = 1;
  43. if (!empty($food_category_id)){
  44. $where['food_category_id'] = $food_category_id;
  45. }
  46. $list = LifeFood::where($where)
  47. ->select(['food_id','food_name'])
  48. ->get()
  49. ->toArray();
  50. return $list;
  51. }
  52. /**
  53. * Notes:修改健康美食
  54. * @param string $food_name
  55. * @param int $food_id
  56. * @return int
  57. * User: ZQ
  58. * Date: 2022/10/17
  59. */
  60. public static function updateFood($food_silde, $food_shop_id, $food_storage, $food_packaging, $food_varieties, $food_attr, $food_postage_id, $food_weight, $food_id, $food_name, $food_img, $food_price, $food_category_id, $food_pack_price, $food_materials, $food_condiment, $food_type, $food_package, $food_label, $food_status, $food_content,$food_cater_time,$food_cater_type,$food_package_num, $food_week, $admin_id)
  61. {
  62. LifeFood::affairBegin();
  63. try {
  64. $where = [];
  65. $where['food_id'] = $food_id;
  66. $data = [];
  67. $data['food_name'] = $food_name;
  68. $data['food_img'] = $food_img;
  69. $data['food_price'] = $food_price;
  70. $data['food_category_id'] = $food_category_id;
  71. $data['food_pack_price'] = $food_pack_price;
  72. $data['food_materials'] = json_encode($food_materials);
  73. $data['food_condiment'] = json_encode($food_condiment);
  74. $data['food_type'] = $food_type;
  75. $data['food_package'] = $food_package;
  76. $data['food_label'] = $food_label;
  77. $data['food_status'] = $food_status;
  78. $data['food_content'] = $food_content;
  79. $data['food_silde'] = $food_silde;
  80. $data['food_shop_id'] = $food_shop_id;
  81. $data['food_storage'] = $food_storage;
  82. $data['food_packaging'] = $food_packaging;
  83. $data['food_varieties'] = $food_varieties;
  84. $data['food_attr'] = $food_attr;
  85. $data['food_postage_id'] = $food_postage_id;
  86. $data['food_weight'] = $food_weight;
  87. $data['food_cater_time'] = $food_cater_time;
  88. $data['food_cater_type'] = $food_cater_type;
  89. $data['food_package_num'] = $food_package_num;
  90. $data['food_week'] = $food_week ? implode(',',$food_week) : '';
  91. $data['food_update_time'] = time();
  92. $result = LifeFood::where($where)->update($data);
  93. if ($result !== false){
  94. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改健康美食-编号: ' . $food_id;
  95. plog('life-food-update', '悦活-健康美食-修改健康美食', $msg);
  96. LifeFood::affairCommit();
  97. return true;
  98. }
  99. throw new \Exception('操作失败!');
  100. }catch (\Exception $exception){
  101. LifeFood::affairRollback();
  102. throw new \Exception($exception->getMessage(), 500);
  103. }
  104. }
  105. /**
  106. * Notes:删除健康美食
  107. * @param int $food_id
  108. * @return int
  109. * User: ZQ
  110. * Date: 2022/10/17
  111. */
  112. public static function delFood($food_id,$admin_id)
  113. {
  114. LifeFood::affairBegin();
  115. try {
  116. $where = [];
  117. $where['food_id'] = $food_id;
  118. $data['food_is_del'] = 1;
  119. $result = LifeFood::where($where)->update($data);
  120. if (!empty($result)){
  121. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除健康美食-编号: ' . $food_id;
  122. plog('life-food-delete', '悦活-健康美食-删除健康美食', $msg);
  123. LifeFood::affairCommit();
  124. return true;
  125. }else{
  126. return false;
  127. }
  128. }catch (\Exception $exception){
  129. LifeFood::affairRollback();
  130. throw new \Exception($exception->getMessage(), 500);
  131. }
  132. }
  133. /**
  134. * Notes: 添加健康美食
  135. * @param string $food_name
  136. * @param array $food_rules
  137. * @return int
  138. * User: ZQ
  139. * Date: 2022/10/17
  140. */
  141. public static function insertFood($food_silde, $food_shop_id, $food_storage, $food_packaging, $food_varieties, $food_attr, $food_postage_id, $food_weight, $food_name, $food_img, $food_price, $food_category_id, $food_pack_price, $food_materials, $food_condiment, $food_type, $food_package, $food_label, $food_status, $food_content,$food_cater_time,$food_cater_type,$food_package_num, $food_week, $admin_id)
  142. {
  143. LifeFood::affairBegin();
  144. try {
  145. $data = [];
  146. $data['food_name'] = $food_name;
  147. $data['food_img'] = $food_img;
  148. $data['food_price'] = $food_price;
  149. $data['food_category_id'] = $food_category_id;
  150. $data['food_pack_price'] = $food_pack_price;
  151. $data['food_materials'] = json_encode($food_materials);
  152. $data['food_condiment'] = json_encode($food_condiment);
  153. $data['food_type'] = $food_type;
  154. $data['food_package'] = $food_package;
  155. $data['food_label'] = $food_label;
  156. $data['food_status'] = $food_status;
  157. $data['food_content'] = $food_content;
  158. $data['food_silde'] = $food_silde;
  159. $data['food_shop_id'] = $food_shop_id;
  160. $data['food_storage'] = $food_storage;
  161. $data['food_packaging'] = $food_packaging;
  162. $data['food_varieties'] = $food_varieties;
  163. $data['food_attr'] = $food_attr;
  164. $data['food_postage_id'] = $food_postage_id;
  165. $data['food_weight'] = $food_weight;
  166. $data['food_cater_time'] = $food_cater_time;
  167. $data['food_cater_type'] = $food_cater_type;
  168. $data['food_package_num'] = $food_package_num;
  169. $data['food_week'] = $food_week ? implode(',',$food_week) : '';
  170. $data['food_create_time'] = time();
  171. $result = LifeFood::insertGetId($data);
  172. if (!empty($result)){
  173. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加健康美食-编号: ' . $result;
  174. plog('life-food-create', '悦活-健康美食-添加健康美食', $msg);
  175. LifeFood::affairCommit();
  176. return $result;
  177. }
  178. throw new \Exception('操作失败!');
  179. }catch (\Exception $exception){
  180. LifeFood::affairRollback();
  181. throw new \Exception($exception->getMessage(), 500);
  182. }
  183. }
  184. /**
  185. * Notes:查询健康美食
  186. * @param int $food_id
  187. * @return int
  188. * User: ZQ
  189. * Date: 2022/10/17
  190. */
  191. public static function foodInfo($food_id)
  192. {
  193. $where = [];
  194. $where['food_id'] = $food_id;
  195. $result = LifeFood::where($where)
  196. ->leftJoin('category','category_id','=','life_healthy_food.food_category_id')
  197. ->first(['life_healthy_food.*','category.category_name']);
  198. if (!empty($result)){
  199. $food_package= explode(',',$result['food_package']);
  200. if (!empty($food_package)){
  201. for ($i=0;$i<count($food_package);$i++){
  202. $intval[] = (int)$food_package[$i];
  203. }
  204. $result['food_package'] = $intval;
  205. }
  206. $result['food_materials'] = json_decode($result['food_materials'],true);
  207. $result['food_condiment'] = json_decode($result['food_condiment'],true);
  208. $result['food_create_time'] = date('Y-m-d H:i:s',$result['food_create_time']);
  209. $result['food_silde'] = explode(',',$result['food_silde']);
  210. $result['food_week'] = explode(',',$result['food_week']);
  211. if (!empty($result['food_update_time'])){
  212. $result['food_update_time'] = date('Y-m-d H:i:s',$result['food_update_time']);
  213. }
  214. }
  215. return $result;
  216. }
  217. /**
  218. * Notes:修改健康美食状态
  219. * @param string $food_name
  220. * @param int $food_status
  221. * @return int
  222. * User: ZQ
  223. * Date: 2022/9/15
  224. */
  225. public static function updateStatus($food_id, $food_status)
  226. {
  227. LifeFood::affairBegin();
  228. try {
  229. $where = [];
  230. $where['food_id'] = $food_id;
  231. $data = [];
  232. $data['food_status'] = $food_status;
  233. $result = LifeFood::where($where)->update($data);
  234. if ($result !== false){
  235. LifeFood::affairCommit();
  236. return true;
  237. }
  238. throw new \Exception('操作失败!');
  239. }catch (\Exception $exception){
  240. LifeFood::affairRollback();
  241. throw new \Exception($exception->getMessage(), 500);
  242. }
  243. }
  244. }