WechatCard.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\wechat;
  12. use app\controller\admin\AuthController;
  13. use app\services\wechat\WechatCardServices;
  14. use think\facade\App;
  15. /**
  16. * 微信卡券
  17. * Class WechatCard
  18. * @package app\controller\admin\v1\application\wechat
  19. */
  20. class WechatCard extends AuthController
  21. {
  22. /**
  23. * WechatCard constructor.
  24. * @param App $app
  25. * @param WechatCardServices $services
  26. */
  27. public function __construct(App $app, WechatCardServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. public function index()
  33. {
  34. $where = $this->request->postMore([
  35. ['kerword', ''],
  36. ['status', '']
  37. ]);
  38. return app('json')->success($this->services->getList($where));
  39. }
  40. /**
  41. * 获取微信会员卡信息
  42. * @return mixed
  43. */
  44. public function info()
  45. {
  46. return $this->success($this->services->getInfo());
  47. }
  48. public function create()
  49. {
  50. return $this->success($this->services->createForm());
  51. }
  52. /**
  53. * 添加|编辑会员卡
  54. * @return mixed
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\DbException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. */
  59. public function save()
  60. {
  61. $data = $this->request->postMore([
  62. ['brand_name', ''],
  63. ['title', ''],
  64. ['logo_url', ''],
  65. ['service_phone', ''],
  66. ['background_pic_url', ''],
  67. ['color', ''],
  68. ['notice', ''],
  69. ['description', ''],
  70. ['center_title', ''],
  71. ['center_sub_title', ''],
  72. ['center_url', ''],
  73. ['prerogative', ''],
  74. ['custom_cell', []],
  75. ]);
  76. if (!$data['brand_name']) return app('json')->fail('请输入商户名称');
  77. if (!$data['title']) return app('json')->fail('请输入卡券名称');
  78. if (!$data['logo_url']) return app('json')->fail('请选择LOGO');
  79. if (!$data['service_phone']) return app('json')->fail('请输入正确手机号');
  80. $this->services->save($data);
  81. return app('json')->success('设置成功');
  82. }
  83. public function edit($id)
  84. {
  85. if (!$id) {
  86. return $this->fail('缺少参数');
  87. }
  88. $card = $this->dao->get($id);
  89. if (!$card) {
  90. throw new AdminException('卡券不存在!');
  91. }
  92. return $this->success($this->services->createForm($card));
  93. }
  94. public function setShow($id, $is_show)
  95. {
  96. if (!$id)
  97. return app('json')->fail('数据不存在');
  98. return app('json')->success($this->services->isShow((int)$id, $is_show));
  99. }
  100. public function delete($id)
  101. {
  102. if (!$id)
  103. return app('json')->fail('数据不存在');
  104. $this->services->delete($id);
  105. return app('json')->success('删除成功');
  106. }
  107. }