ShopList.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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->assign('typeList', StockConfig::where('type_id', 'variety_name')->order('sort desc')->column('title','id'));
  30. $this->assign('packingList', StockConfig::where('type_id', 'packing_box')->column('title','id'));
  31. $this->relationField=['customer','staff'];
  32. }
  33. #[Route('GET,POST','specs')]
  34. public function specs()
  35. {
  36. if($this->request->isAjax()){
  37. $ids = $this->request->post('ids/d', 0);
  38. $params = $this->request->post('');
  39. if(empty($params['all_data']) || empty($ids)) return resp_json(0, '参数错误');
  40. $this->model->where('id', $ids)->save([
  41. 'type_spec' => json_encode($params['all_data'], JSON_UNESCAPED_UNICODE),
  42. ]);
  43. return resp_json(200,'操作成功');
  44. }else{
  45. $ids =$this->request->get('ids/d', 0);
  46. $rows = $this->model::where('id', $ids)->where('status', 1)->find();
  47. $this->assign('ids', $ids);
  48. $this->assign('row', $rows->type_spec??'');
  49. return $this->fetch();
  50. }
  51. }
  52. #[Route('GET','get_box')]
  53. public function get_box()
  54. {
  55. if($this->request->isAjax()){
  56. $ids = $this->request->get('ids/d', 0);
  57. $type_id = $this->request->get('type_id/d', 0);
  58. if(empty($ids) || empty($type_id)) return resp_json(0, '参数错误');
  59. $customer_id = $this->model::where('id', $ids)->value('customer_id');
  60. $rows = CustomerSpecBack::alias('a')
  61. ->leftjoin('product_config b', 'a.product_id=b.id')
  62. ->field('a.*,b.title')
  63. ->where('a.type_id', $type_id)
  64. ->where('a.customer_id', $customer_id)
  65. ->where('a.status', CustomerSpecBack::NORMAL)
  66. ->order('a.sort desc')->select();
  67. return json($rows, 200);
  68. }
  69. }
  70. }