ShopList.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller\shop;
  4. use app\common\controller\Backend;
  5. use think\annotation\route\Group;
  6. use think\annotation\route\Route;
  7. use app\admin\traits\Actions;
  8. use app\common\model\Customer;
  9. use app\common\model\User;
  10. use app\common\model\StockConfig;
  11. use app\common\model\CustomerSpecBack;
  12. use app\api\service\SpecService;
  13. use app\common\model\ShopList as ShopListModel;
  14. #[Group("shop/shop_list")]
  15. class ShopList extends Backend
  16. {
  17. use Actions{
  18. add as protected _add;
  19. edit as protected _edit;
  20. }
  21. protected function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = new ShopListModel();
  25. $this->assign('customerList', Customer::where('status', 1)->column('name','id'));
  26. $this->assign('platformList', site_config('addonsd.platform_list'));
  27. $this->assign('userList', User::where('status',Customer::STATUS_NORMAL)->column('nickname','id'));
  28. $this->assign('fieldList', StockConfig::where('type_id', 'variety_name')->order('sort desc')->column('title','id'));
  29. $this->relationField=['customer','staff'];
  30. }
  31. #[Route('GET,POST','specs')]
  32. public function specs()
  33. {
  34. if($this->request->isAjax()){
  35. $ids = $this->request->post('ids/d', 0);
  36. $params = $this->request->post('');
  37. if(empty($params['variety']) || empty($ids) || empty($params['type_box'])) return resp_json(0, '参数错误');
  38. $this->model->where('id', $ids)->save([
  39. 'variety' => json_encode($params['variety'], JSON_UNESCAPED_UNICODE),
  40. 'type_spec' => json_encode($params['type_box'], JSON_UNESCAPED_UNICODE),
  41. ]);
  42. return resp_json(200,'操作成功');
  43. }else{
  44. $ids = $this->request->get('ids/d', 0);
  45. $rows = $this->model::find($ids);
  46. $rows->variety = $rows->variety? json_decode($rows->variety, true) : [];
  47. $rows->type_spec = $rows->type_spec? json_decode($rows->type_spec, true) : [];
  48. $this->assign('row', $rows);
  49. return $this->fetch();
  50. }
  51. }
  52. #[Route('GET','get_box')]
  53. public function get_box()
  54. {
  55. if($this->request->isAjax()){
  56. $result = [];
  57. $customer_id = $this->request->get('customer_id/d', 0);
  58. $type_id = $this->request->get('type_id/d', 0);
  59. if(empty($type_id) || empty($customer_id)) return resp_json(0, '参数错误');
  60. $rows = CustomerSpecBack::where('customer_id', $customer_id)->order('sort desc')->find();
  61. if($rows->specs){
  62. $specs = json_decode($rows->specs, true);
  63. $result = SpecService::getSpecsList($type_id, $specs);
  64. }
  65. return json($result, 200);
  66. }
  67. }
  68. }