Card.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 crmeb\services\{ExpressService,
  10. JsonService,
  11. JsonService as Json,
  12. MiniProgramService,
  13. WechatService,
  14. FormBuilder as Form,
  15. CacheService,
  16. UtilService as Util};
  17. use Monolog\Handler\IFTTTHandler;
  18. use think\facade\Route as Url;
  19. use think\facade\Validate;
  20. Use app\admin\model\card\Card as model;
  21. /**
  22. * 订单管理控制器 同一个订单表放在一个控制器
  23. * Class StoreOrder
  24. * @package app\admin\controller\store
  25. */
  26. class Card extends AuthController
  27. {
  28. /**
  29. * @return mixed
  30. */
  31. public function index()
  32. {
  33. return $this->fetch();
  34. }
  35. public function list()
  36. {
  37. $where = Util::getMore([
  38. ['page', 1],
  39. ['limit', 20],
  40. ['name', ''],
  41. ]);
  42. return Json::successlayui(model::list($where));
  43. }
  44. /**
  45. * 显示创建资源表单页.
  46. *
  47. * @return \think\Response
  48. */
  49. public function create($id = 0)
  50. {
  51. $list = [
  52. 'id' => '',
  53. 'name' => '',
  54. 'time' => '',
  55. 'image' =>'',
  56. 'introduce' => '',
  57. 'start_week' => '',
  58. 'end_week' => '',
  59. 'price' => '',
  60. 'details_image' => '',
  61. 'info' => '',
  62. ];
  63. if ($id){
  64. $data = \app\admin\model\card\Card::where('id', $id)->find()->toArray();
  65. foreach ($data as $k => $v){
  66. $list[$k] = $v;
  67. if ($k == 'introduce'){
  68. $list[$k] = html_entity_decode($v);
  69. }
  70. }
  71. }
  72. $this->assign('list', $list);
  73. $this->assign('id', $id);
  74. return $this->fetch();
  75. }
  76. public function save()
  77. {
  78. $model = new model;
  79. $data = Util::postMore([
  80. 'id',
  81. 'name',
  82. 'time',
  83. 'price',
  84. 'start_week',
  85. 'end_week',
  86. 'introduce',
  87. 'image',
  88. 'details_image',
  89. 'info',
  90. ]);
  91. if ($data['id']){
  92. $list = \app\admin\model\card\Card::where('id', $data['id'])->find();
  93. $list['name'] = $data['name'];
  94. $list['time'] = $data['time'];
  95. $list['price'] = $data['price'];
  96. $list['start_week'] = $data['start_week'];
  97. $list['end_week'] = $data['end_week'];
  98. $list['introduce'] = $data['introduce'];
  99. $list['image'] = $data['image'];
  100. $list['details_image'] = $data['details_image'];
  101. $list['info'] = $data['info'];
  102. $res = $list->save();
  103. }else{
  104. $res = $model->save($data);
  105. }
  106. if ($res) return Json::successful('添加图文成功!');
  107. return Json::fail('添加失败');
  108. }
  109. /**
  110. * 显示创建资源表单页.
  111. *
  112. * @return \think\Response
  113. */
  114. public function edit($id = 0)
  115. {
  116. $data = model::find($id);
  117. $f = [];
  118. $f[] = Form::input('name', '分类名称', $data['name'])->required();
  119. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  120. ['value' => 1, 'label' => '陪诊'],
  121. ['value' => 2, 'label' => '代办'],
  122. ])->filterable(true)->required();
  123. $f[] = Form::input('price', '金额', $data['price'])->required();
  124. $f[] = Form::radio('status', '状态', (string)$data['status'])->options([['value' => 0, 'label' => '禁用'], ['value' => 1, 'label' => '正常']]);
  125. $f[] = Form::hidden('id', $id);
  126. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  127. $this->assign(compact('form'));
  128. return $this->fetch('public/form-builder');
  129. }
  130. /**
  131. * 修改
  132. * @return void
  133. * @throws \think\db\exception\DataNotFoundException
  134. * @throws \think\db\exception\DbException
  135. * @throws \think\db\exception\ModelNotFoundException
  136. */
  137. public function update()
  138. {
  139. $model = new model;
  140. $data = Util::postMore([
  141. 'name',
  142. 'type',
  143. 'price',
  144. 'status',
  145. 'id'
  146. ]);
  147. $details = $model->find($data['id']);
  148. $details['name'] = $data['name'];
  149. $details['type'] = $data['type'];
  150. $details['price'] = $data['price'];
  151. $details['status'] = $data['status'];
  152. $res = $details->save();
  153. if ($res) return Json::successful('修改成功');
  154. return Json::fail('修改失败');
  155. }
  156. /**
  157. * 删除
  158. * @param $id
  159. * @return void
  160. * @throws \Exception
  161. */
  162. public function delete($id)
  163. {
  164. if (!$id) return Json::fail('删除失败');
  165. $model = new model;
  166. $res = model::destroy($id);
  167. if ($res){
  168. return Json::success('删除成功!');
  169. }else{
  170. return Json::fail($model->getErrorInfo());
  171. }
  172. }
  173. /**
  174. * 设置单个产品上架|下架
  175. *
  176. * @return json
  177. */
  178. public function set_show($is_show = '', $id = '')
  179. {
  180. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  181. $res = model::where(['id' => $id])->update(['status' => (int)$is_show]);
  182. if ($res) {
  183. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  184. } else {
  185. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  186. }
  187. }
  188. }