ProductRule.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\system\controller\v1;
  3. use app\BaseController;
  4. use app\model\system\ProductRule as ProductRuleModel;
  5. use library\services\UtilService;
  6. use think\Request;
  7. /**
  8. * 规则管理
  9. * Class ProductRule
  10. * @package app\system\controller\v1
  11. */
  12. class ProductRule extends BaseController
  13. {
  14. /**
  15. * 显示资源列表
  16. *
  17. * @return \think\Response
  18. */
  19. public function index()
  20. {
  21. $where = UtilService::getMore([
  22. ['page', 1],
  23. ['limit', 15],
  24. ['rule_name','']
  25. ]);
  26. // if($this->merId){
  27. // $where['mer_id'] = $this->merId;
  28. // }
  29. $list = ProductRuleModel::sysPage($where);
  30. return app('json')->success($list);
  31. }
  32. /**
  33. * 保存新建的资源
  34. *
  35. * @param \think\Request $request
  36. * @return \think\Response
  37. */
  38. public function save(Request $request,$id)
  39. {
  40. $data = UtilService::getMore([
  41. ['rule_name',''],
  42. ['spec',[]]
  43. ]);
  44. //$data['mer_id'] = $this->merId ?: '';
  45. if ($data['rule_name'] == '') return app('json')->fail('请输入规则名称');
  46. if (!$data['spec']) return app('json')->fail('缺少规则值');
  47. $data['rule_value'] = json_encode($data['spec']);
  48. unset($data['spec']);
  49. if ($id){
  50. $rule = ProductRuleModel::get($id);
  51. if (!$rule) return app('json')->fail('数据不存在');
  52. ProductRuleModel::edit($data, $id);
  53. return app('json')->success('编辑成功!');
  54. }else{
  55. ProductRuleModel::create($data);
  56. return app('json')->success('规则添加成功!');
  57. }
  58. }
  59. /**
  60. * 显示指定的资源
  61. *
  62. * @param int $id
  63. * @return \think\Response
  64. */
  65. public function read($id)
  66. {
  67. $info = ProductRuleModel::sysInfo($id);
  68. return app('json')->success($info);
  69. }
  70. /**
  71. * 删除指定资源
  72. *
  73. * @param int $id
  74. * @return \think\Response
  75. */
  76. public function delete()
  77. {
  78. $data = UtilService::getMore([
  79. ['ids','']
  80. ]);
  81. if ($data['ids']=='') return app('json')->fail('请至少选择一条数据');
  82. $ids = strval($data['ids']);
  83. $res = ProductRuleModel::whereIn('id',$ids)->delete();
  84. if (!$res)
  85. return app('json')->fail(ProductRuleModel::getErrorInfo('删除失败,请稍候再试!'));
  86. else
  87. return app('json')->success('删除成功!');
  88. }
  89. }