ShopList.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\CustomerSpec;
  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($ids)) return resp_json(0, '请选择店铺规格');
  40. $this->model->where('id', $ids)->save([
  41. 'type_spec' => isset($params['all_data'])?json_encode($params['all_data'], JSON_UNESCAPED_UNICODE):null,
  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 = CustomerSpec::alias('a')
  61. ->leftjoin('product_config b', 'a.product_id=b.id') //规格
  62. ->leftjoin('stock_config c', 'a.type_id=c.id') //品种
  63. ->leftjoin('stock_config d', 'a.box_id=d.id') //包装箱
  64. ->field('a.*,b.title,c.title as type_name,d.title as box_name')
  65. ->field('a.*,b.title')
  66. ->where('a.type_id', $type_id)
  67. ->where('a.customer_id', $customer_id)
  68. ->where('a.status', CustomerSpec::NORMAL)
  69. ->order('a.sort desc')->select();
  70. return json($rows, 200);
  71. }
  72. }
  73. }