CardProject.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\card;
  8. use app\admin\controller\AuthController;
  9. use app\admin\model\diagnosis\DiagnosisCate;
  10. use crmeb\services\{ExpressService,
  11. JsonService,
  12. JsonService as Json,
  13. MiniProgramService,
  14. WechatService,
  15. FormBuilder as Form,
  16. CacheService,
  17. UtilService as Util};
  18. use think\facade\Route as Url;
  19. use think\facade\Validate;
  20. Use app\admin\model\card\CardProject as model;
  21. /**
  22. * 订单管理控制器 同一个订单表放在一个控制器
  23. * Class StoreOrder
  24. * @package app\admin\controller\store
  25. */
  26. class CardProject extends AuthController
  27. {
  28. /**
  29. * @return mixed
  30. */
  31. public function index($id)
  32. {
  33. $this->assign('id', $id);
  34. return $this->fetch();
  35. }
  36. public function list()
  37. {
  38. $where = Util::getMore([
  39. ['page', 1],
  40. ['limit', 20],
  41. ['id', ''],
  42. ]);
  43. return Json::successlayui(model::list($where));
  44. }
  45. /**
  46. * 显示创建资源表单页.
  47. *
  48. * @return \think\Response
  49. */
  50. public function create($id = 0)
  51. {
  52. $f = [];
  53. $f[] = Form::hidden('card_id', $id);
  54. $f[] = Form::selectMultiple('c_id', '绑定内容', [])->options(
  55. DiagnosisCate::field('id as value,name as label')->select()->toArray()
  56. )->filterable(true)->required();
  57. $f[] = Form::select('type', '选择类型', '')->options([
  58. ['value' => 1, 'label' => '限时'],
  59. ['value' => 2, 'label' => '限次'],
  60. ])->filterable(true)->required();
  61. $f[] = Form::input('number', '次数');
  62. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  63. $this->assign(compact('form'));
  64. return $this->fetch('public/form-builder');
  65. }
  66. public function save()
  67. {
  68. $model = new model;
  69. $data = Util::postMore([
  70. 'card_id',
  71. 'c_id',
  72. 'type',
  73. 'number',
  74. ]);
  75. $data['c_id'] = implode(',', $data['c_id']);
  76. if ($data['type'] == 2){
  77. if (empty($data['number'])) return Json::successful('选择限次,请输入次数');
  78. }
  79. $res = $model->save($data);
  80. if ($res) return Json::successful('添加成功');
  81. return Json::fail('添加失败');
  82. }
  83. /**
  84. * 显示创建资源表单页.
  85. *
  86. * @return \think\Response
  87. */
  88. public function edit($id = 0)
  89. {
  90. $data = model::find($id);
  91. $f = [];
  92. $f[] = Form::selectMultiple('c_id', '绑定内容', explode(',', $data['c_id']))->options(
  93. DiagnosisCate::field('id as value,name as label')->select()->toArray()
  94. )->filterable(true)->required();
  95. $f[] = Form::select('type', '选择类型', (string)$data['type'])->options([
  96. ['value' => 1, 'label' => '限时'],
  97. ['value' => 2, 'label' => '限次'],
  98. ])->filterable(true)->required();
  99. $f[] = Form::input('number', '次数', $data['number']);
  100. $f[] = Form::hidden('id', $id);
  101. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  102. $this->assign(compact('form'));
  103. return $this->fetch('public/form-builder');
  104. }
  105. /**
  106. * 修改
  107. * @return void
  108. * @throws \think\db\exception\DataNotFoundException
  109. * @throws \think\db\exception\DbException
  110. * @throws \think\db\exception\ModelNotFoundException
  111. */
  112. public function update()
  113. {
  114. $model = new model;
  115. $data = Util::postMore([
  116. 'c_id',
  117. 'type',
  118. 'number',
  119. 'id'
  120. ]);
  121. $details = $model->find($data['id']);
  122. $details['c_id'] = $data['c_id'];
  123. $details['type'] = $data['type'];
  124. $details['number'] = $data['number'];
  125. $res = $details->save();
  126. if ($res) return Json::successful('修改成功');
  127. return Json::fail('修改失败');
  128. }
  129. /**
  130. * 删除
  131. * @param $id
  132. * @return void
  133. * @throws \Exception
  134. */
  135. public function delete($id)
  136. {
  137. if (!$id) return Json::fail('删除失败');
  138. $model = new model;
  139. $res = model::destroy($id);
  140. if ($res){
  141. return Json::success('删除成功!');
  142. }else{
  143. return Json::fail($model->getErrorInfo());
  144. }
  145. }
  146. /**
  147. * 设置单个产品上架|下架
  148. *
  149. * @return json
  150. */
  151. public function set_show($is_show = '', $id = '')
  152. {
  153. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  154. $res = model::where(['id' => $id])->update(['status' => (int)$is_show]);
  155. if ($res) {
  156. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  157. } else {
  158. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  159. }
  160. }
  161. }