ShopList.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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', 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. $field_name= $this->request->post('field_name');
  37. $type_id = $this->request->post('type_id');
  38. $specs = $this->request->post('type_box');
  39. $specsList = [];
  40. foreach ($specs as $item) {
  41. if(empty($item['price'])) return resp_json(0, '请填写发货价格');
  42. $specsList[] = ['name'=>$item['name'], 'price'=> $item['price']];
  43. }
  44. $row = $this->model::find($ids);
  45. $row->type_spec = json_encode(['field_name'=>['type_id'=>$type_id, 'field_name'=>$field_name], 'specs'=> $specsList], JSON_UNESCAPED_UNICODE);
  46. $row->save();
  47. return resp_json(200,'操作成功');
  48. }else{
  49. $ids = $this->request->get('ids/d', 0);
  50. $rows = $this->model::find($ids);
  51. $this->assign('row', $rows);
  52. return $this->fetch();
  53. }
  54. }
  55. #[Route('GET','get_box')]
  56. public function get_box()
  57. {
  58. if($this->request->isAjax()){
  59. $customer_id = $this->request->get('customer_id/d', 0);
  60. $type_id = $this->request->get('type_id/d', 0);
  61. if(empty($type_id) || empty($customer_id)) return resp_json(0, '参数错误');
  62. $rows = $this->model::where('customer_id', $customer_id)->order('sort desc')->find();
  63. if($rows->specs){
  64. $specs = json_decode($rows->specs, true);
  65. dump($specs);die;
  66. foreach ($specs['specs'] as $item) {
  67. }
  68. }
  69. return json($rows, 200);
  70. }
  71. }
  72. }