CardProject.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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::select('c_id', '绑定内容', 0)->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. if ($data['type'] == 2){
  76. if (empty($data['number'])) return Json::successful('选择限次,请输入次数');
  77. }
  78. $res = $model->save($data);
  79. if ($res) return Json::successful('添加成功');
  80. return Json::fail('添加失败');
  81. }
  82. /**
  83. * 显示创建资源表单页.
  84. *
  85. * @return \think\Response
  86. */
  87. public function edit($id = 0)
  88. {
  89. $data = model::find($id);
  90. $f = [];
  91. $f[] = Form::select('c_id', '绑定内容', (string)$data['c_id'])->options(
  92. DiagnosisCate::field('id as value,name as label')->select()->toArray()
  93. )->filterable(true)->required();
  94. $f[] = Form::select('type', '选择类型', (string)$data['type'])->options([
  95. ['value' => 1, 'label' => '限时'],
  96. ['value' => 2, 'label' => '限次'],
  97. ])->filterable(true)->required();
  98. $f[] = Form::input('number', '次数', $data['number']);
  99. $f[] = Form::hidden('id', $id);
  100. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  101. $this->assign(compact('form'));
  102. return $this->fetch('public/form-builder');
  103. }
  104. /**
  105. * 修改
  106. * @return void
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\DbException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. */
  111. public function update()
  112. {
  113. $model = new model;
  114. $data = Util::postMore([
  115. 'c_id',
  116. 'type',
  117. 'number',
  118. 'id'
  119. ]);
  120. $details = $model->find($data['id']);
  121. $details['c_id'] = $data['c_id'];
  122. $details['type'] = $data['type'];
  123. $details['number'] = $data['number'];
  124. $res = $details->save();
  125. if ($res) return Json::successful('修改成功');
  126. return Json::fail('修改失败');
  127. }
  128. /**
  129. * 删除
  130. * @param $id
  131. * @return void
  132. * @throws \Exception
  133. */
  134. public function delete($id)
  135. {
  136. if (!$id) return Json::fail('删除失败');
  137. $model = new model;
  138. $res = model::destroy($id);
  139. if ($res){
  140. return Json::success('删除成功!');
  141. }else{
  142. return Json::fail($model->getErrorInfo());
  143. }
  144. }
  145. /**
  146. * 设置单个产品上架|下架
  147. *
  148. * @return json
  149. */
  150. public function set_show($is_show = '', $id = '')
  151. {
  152. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  153. $res = model::where(['id' => $id])->update(['status' => (int)$is_show]);
  154. if ($res) {
  155. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  156. } else {
  157. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  158. }
  159. }
  160. }