StoreProductRule.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\store\product;
  12. use app\controller\store\AuthController;
  13. use app\jobs\BatchHandleJob;
  14. use app\services\other\queue\QueueServices;
  15. use app\services\product\sku\StoreProductRuleServices;
  16. use think\facade\App;
  17. /**
  18. * 规则管理
  19. * Class StoreProductRule
  20. * @package app\controller\store\product
  21. */
  22. class StoreProductRule extends AuthController
  23. {
  24. public function __construct(App $app, StoreProductRuleServices $service)
  25. {
  26. parent::__construct($app);
  27. $this->services = $service;
  28. }
  29. /**
  30. * 规格列表
  31. * @return mixed
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function index()
  37. {
  38. $where = $this->request->getMore([
  39. ['rule_name', '']
  40. ]);
  41. $where['type'] = 1;
  42. $where['relation_id'] = $this->storeId;
  43. $list = $this->services->getList($where);
  44. return $this->success($list);
  45. }
  46. /**
  47. * 保存规格
  48. * @param $id
  49. * @return mixed
  50. */
  51. public function save($id)
  52. {
  53. $data = $this->request->postMore([
  54. ['rule_name', ''],
  55. ['spec', []]
  56. ]);
  57. if (!$data['rule_name']) {
  58. return $this->fail('请输入分类名称');
  59. }
  60. $data['type'] = 1;
  61. $data['relation_id'] = $this->storeId;
  62. $this->services->save($id, $data, 1, (int)$this->storeId);
  63. return $this->success('保存成功!');
  64. }
  65. /**
  66. * 获取规格信息
  67. * @param $id
  68. * @return mixed
  69. */
  70. public function read($id)
  71. {
  72. $info = $this->services->getInfo($id);
  73. return $this->success($info);
  74. }
  75. /**
  76. * 删除指定资源
  77. * @param $id
  78. * @return mixed
  79. */
  80. public function delete($id)
  81. {
  82. if (!$id) {
  83. return $this->fail('缺少ID');
  84. }
  85. $info = $this->services->getInfo((int)$id);
  86. if (!$info) {
  87. return $this->fail('删除的数据不存在');
  88. }
  89. $this->services->delete($id);
  90. return $this->success('删除成功!');
  91. }
  92. }