Card.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. ];
  62. if ($id){
  63. $data = \app\admin\model\card\Card::where('id', $id)->find()->toArray();
  64. foreach ($data as $k => $v){
  65. $list[$k] = $v;
  66. if ($k == 'introduce'){
  67. $list[$k] = html_entity_decode($v);
  68. }
  69. }
  70. }
  71. $this->assign('list', $list);
  72. $this->assign('id', $id);
  73. return $this->fetch();
  74. }
  75. public function save()
  76. {
  77. $model = new model;
  78. $data = Util::postMore([
  79. 'id',
  80. 'name',
  81. 'time',
  82. 'price',
  83. 'start_week',
  84. 'end_week',
  85. 'introduce',
  86. 'image',
  87. 'details_image',
  88. ]);
  89. if ($data['id']){
  90. $list = \app\admin\model\card\Card::where('id', $data['id'])->find();
  91. $list['name'] = $data['name'];
  92. $list['time'] = $data['time'];
  93. $list['price'] = $data['price'];
  94. $list['start_week'] = $data['start_week'];
  95. $list['end_week'] = $data['end_week'];
  96. $list['introduce'] = $data['introduce'];
  97. $list['image'] = $data['image'];
  98. $list['details_image'] = $data['details_image'];
  99. $res = $list->save();
  100. }else{
  101. $res = $model->save($data);
  102. }
  103. if ($res) return Json::successful('添加图文成功!');
  104. return Json::fail('添加失败');
  105. }
  106. /**
  107. * 显示创建资源表单页.
  108. *
  109. * @return \think\Response
  110. */
  111. public function edit($id = 0)
  112. {
  113. $data = model::find($id);
  114. $f = [];
  115. $f[] = Form::input('name', '分类名称', $data['name'])->required();
  116. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  117. ['value' => 1, 'label' => '陪诊'],
  118. ['value' => 2, 'label' => '代办'],
  119. ])->filterable(true)->required();
  120. $f[] = Form::input('price', '金额', $data['price'])->required();
  121. $f[] = Form::radio('status', '状态', (string)$data['status'])->options([['value' => 0, 'label' => '禁用'], ['value' => 1, 'label' => '正常']]);
  122. $f[] = Form::hidden('id', $id);
  123. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  124. $this->assign(compact('form'));
  125. return $this->fetch('public/form-builder');
  126. }
  127. /**
  128. * 修改
  129. * @return void
  130. * @throws \think\db\exception\DataNotFoundException
  131. * @throws \think\db\exception\DbException
  132. * @throws \think\db\exception\ModelNotFoundException
  133. */
  134. public function update()
  135. {
  136. $model = new model;
  137. $data = Util::postMore([
  138. 'name',
  139. 'type',
  140. 'price',
  141. 'status',
  142. 'id'
  143. ]);
  144. $details = $model->find($data['id']);
  145. $details['name'] = $data['name'];
  146. $details['type'] = $data['type'];
  147. $details['price'] = $data['price'];
  148. $details['status'] = $data['status'];
  149. $res = $details->save();
  150. if ($res) return Json::successful('修改成功');
  151. return Json::fail('修改失败');
  152. }
  153. /**
  154. * 删除
  155. * @param $id
  156. * @return void
  157. * @throws \Exception
  158. */
  159. public function delete($id)
  160. {
  161. if (!$id) return Json::fail('删除失败');
  162. $model = new model;
  163. $res = model::destroy($id);
  164. if ($res){
  165. return Json::success('删除成功!');
  166. }else{
  167. return Json::fail($model->getErrorInfo());
  168. }
  169. }
  170. /**
  171. * 设置单个产品上架|下架
  172. *
  173. * @return json
  174. */
  175. public function set_show($is_show = '', $id = '')
  176. {
  177. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  178. $res = model::where(['id' => $id])->update(['status' => (int)$is_show]);
  179. if ($res) {
  180. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  181. } else {
  182. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  183. }
  184. }
  185. }