Card.php 5.6 KB

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