StoreProductRule.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\admin\v1\product;
  12. use app\controller\admin\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\admin\v1\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'] = 0;
  42. $where['relation_id'] = 0;
  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. $this->services->save($id, $data);
  61. return $this->success('保存成功!');
  62. }
  63. /**
  64. * 获取规格信息
  65. * @param $id
  66. * @return mixed
  67. */
  68. public function read($id)
  69. {
  70. $info = $this->services->getInfo((int)$id);
  71. return $this->success($info);
  72. }
  73. /**
  74. * 删除指定资源
  75. *
  76. * @param int $id
  77. * @return \think\Response
  78. */
  79. public function delete($id)
  80. {
  81. if (!$id) {
  82. return $this->fail('缺少ID');
  83. }
  84. $info = $this->services->getInfo((int)$id);
  85. if (!$info) {
  86. return $this->fail('删除的数据不存在');
  87. }
  88. $this->services->delete($id);
  89. return $this->success('删除成功!');
  90. }
  91. }