ShopList.php 2.6 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\ProductConfig;
  12. use think\Response;
  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',Customer::STATUS_NORMAL)->column('name','id'));
  26. $this->assign('platformList', config("app.platform_list"));
  27. $this->assign('userList', User::where('status',Customer::STATUS_NORMAL)->column('nickname','id'));
  28. $this->relationField=['customer','staff'];
  29. }
  30. #[Route('GET,POST','specs')]
  31. public function specs()
  32. {
  33. if($this->request->isAjax()){
  34. $ids = $this->request->post('ids/d', 0);
  35. $field_name= $this->request->post('field_name');
  36. $type_id = $this->request->post('type_id');
  37. $specs = $this->request->post('type_box');
  38. $specsList = [];
  39. foreach ($specs as $item) {
  40. if(empty($item['price'])) return resp_json(0, '请填写发货价格');
  41. $specsList[] = ['name'=>$item['name'], 'price'=> $item['price']];
  42. }
  43. $row = $this->model::find($ids);
  44. $row->type_spec = json_encode(['field_name'=>['type_id'=>$type_id, 'field_name'=>$field_name], 'specs'=> $specsList], JSON_UNESCAPED_UNICODE);
  45. $row->save();
  46. return resp_json(200,'操作成功');
  47. }else{
  48. $ids = $this->request->get('ids/d', 0);
  49. $rows = $this->model::find($ids);
  50. $fieldList= StockConfig::where('type_id', 'variety_name')->column('field_name','id');
  51. $this->assign('rows', $rows);
  52. $this->assign('fieldList',$fieldList);
  53. return $this->fetch();
  54. }
  55. }
  56. #[Route('GET','get_box')]
  57. public function get_box()
  58. {
  59. if($this->request->isAjax()){
  60. $type_id = $this->request->get('type_id/d', 0);
  61. if(empty($type_id)) return resp_json(0, '参数错误');
  62. $list = ProductConfig::where('type_id', $type_id)->order('sort desc')->field('another_name, title')->select();
  63. return json($list, 200);
  64. }
  65. }
  66. }