WechatQrcode.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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\WechatQrcodeCateServices;
  14. use app\services\wechat\WechatQrcodeRecordServices;
  15. use app\services\wechat\WechatQrcodeServices;
  16. use think\facade\App;
  17. class WechatQrcode extends AuthController
  18. {
  19. protected $qrcodeCateServices;
  20. protected $wechatQrcodeServices;
  21. protected $qrcodeRecordServices;
  22. /**
  23. * WechatQrcode constructor.
  24. * @param App $app
  25. * @param WechatQrcodeCateServices $services
  26. */
  27. public function __construct(App $app, WechatQrcodeCateServices $qrcodeCateServices, WechatQrcodeServices $wechatQrcodeServices, WechatQrcodeRecordServices $qrcodeRecordServices)
  28. {
  29. parent::__construct($app);
  30. $this->qrcodeCateServices = $qrcodeCateServices;
  31. $this->wechatQrcodeServices = $wechatQrcodeServices;
  32. $this->qrcodeRecordServices = $qrcodeRecordServices;
  33. }
  34. /**
  35. * 分类列表
  36. * @return mixed
  37. */
  38. public function getCateList()
  39. {
  40. $data = $this->qrcodeCateServices->getCateList();
  41. $count = $this->qrcodeCateServices->count(['is_del' => 0]);
  42. return app('json')->success(compact('data', 'count'));
  43. }
  44. /**
  45. * 添加编辑表单
  46. * @param $id
  47. * @return mixed
  48. * @throws \FormBuilder\Exception\FormBuilderException
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function createForm($id)
  54. {
  55. return app('json')->success($this->qrcodeCateServices->createForm($id));
  56. }
  57. /**
  58. * 保存数据
  59. * @return mixed
  60. */
  61. public function saveCate()
  62. {
  63. $data = $this->request->postMore([
  64. ['id', 0],
  65. ['cate_name', '']
  66. ]);
  67. $this->qrcodeCateServices->saveData($data);
  68. return app('json')->success('保持成功');
  69. }
  70. /**
  71. * 删除分类
  72. * @param $id
  73. * @return mixed
  74. */
  75. public function delCate($id)
  76. {
  77. $this->qrcodeCateServices->delCate((int)$id);
  78. return app('json')->success('删除成功');
  79. }
  80. /**
  81. * 保存渠道码
  82. * @param $id
  83. * @return mixed
  84. */
  85. public function saveQrcode($id = 0)
  86. {
  87. $data = $this->request->postMore([
  88. ['uid', 0],
  89. ['name', ''],
  90. ['image', ''],
  91. ['cate_id', 0],
  92. ['label_id', []],
  93. ['type', 0],
  94. ['content', ''],
  95. ['time', 0],
  96. ]);
  97. $this->wechatQrcodeServices->saveQrcode($id, $data);
  98. return app('json')->success('保存成功');
  99. }
  100. /**
  101. * 获取渠道码列表
  102. * @return mixed
  103. */
  104. public function qrcodeList()
  105. {
  106. $where = $this->request->getMore([
  107. ['name', ''],
  108. ['cate_id', 0]
  109. ]);
  110. $where['is_del'] = 0;
  111. $data = $this->wechatQrcodeServices->qrcodeList($where);
  112. return app('json')->success($data);
  113. }
  114. /**
  115. * 获取详情
  116. * @param int $id
  117. * @return mixed
  118. */
  119. public function qrcodeInfo($id = 0)
  120. {
  121. if (!$id) return app('json')->fail('参数错误');
  122. $info = $this->wechatQrcodeServices->qrcodeInfo($id);
  123. return app('json')->success($info);
  124. }
  125. /**
  126. * 删除渠道码
  127. * @param int $id
  128. * @return mixed
  129. */
  130. public function delQrcode($id = 0)
  131. {
  132. if (!$id) return app('json')->fail('参数错误');
  133. $this->wechatQrcodeServices->update($id, ['is_del' => 1]);
  134. return app('json')->success('删除成功');
  135. }
  136. /**
  137. * 切换状态
  138. * @param $id
  139. * @param $status
  140. * @return mixed
  141. */
  142. public function setStatus($id, $status)
  143. {
  144. if (!$id) return app('json')->fail('参数错误');
  145. $this->wechatQrcodeServices->update($id, ['status' => $status]);
  146. return app('json')->success('切换成功');
  147. }
  148. /**
  149. * 用户列表
  150. * @param $qid
  151. * @return mixed
  152. * @throws \think\db\exception\DataNotFoundException
  153. * @throws \think\db\exception\DbException
  154. * @throws \think\db\exception\ModelNotFoundException
  155. */
  156. public function userList($qid)
  157. {
  158. return app('json')->success($this->qrcodeRecordServices->userList($qid));
  159. }
  160. /**
  161. * 渠道码统计
  162. * @param $qid
  163. * @return mixed
  164. */
  165. public function qrcodeStatistic($qid)
  166. {
  167. [$time] = $this->request->getMore([
  168. ['time', ''],
  169. ], true);
  170. $where['qid'] = $qid;
  171. return app('json')->success($this->qrcodeRecordServices->qrcodeStatistic($where, $time));
  172. }
  173. }