Serve.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\system\serve;
  12. //use app\validate\admin\serve\ServeValidata;
  13. //use app\services\system\config\SystemConfigServices;
  14. use app\common\repositories\system\config\ConfigValueRepository;
  15. use app\common\repositories\system\merchant\MerchantRepository;
  16. use app\common\repositories\system\serve\ServeOrderRepository;
  17. use app\validate\admin\ExpressValidata;
  18. use app\validate\admin\MealValidata;
  19. use crmeb\basic\BaseController;
  20. use crmeb\services\CrmebServeServices;
  21. use think\App;
  22. use think\facade\Cache;
  23. use app\validate\admin\CrmebServeValidata;
  24. /**
  25. * Class Serve
  26. * @package app\controller\admin\v1\serve
  27. */
  28. class Serve extends BaseController
  29. {
  30. protected $services;
  31. /**
  32. * Serve constructor.
  33. * @param App $app
  34. * @param ServeServices $services
  35. */
  36. public function __construct(App $app, CrmebServeServices $services)
  37. {
  38. parent::__construct($app);
  39. $this->services = $services;
  40. }
  41. /**
  42. * 检测登录
  43. * @return mixed
  44. */
  45. public function is_login()
  46. {
  47. $sms_info = systemConfigNoCache('serve_account');
  48. if ($sms_info) {
  49. return app('json')->success(['status' => true, 'info' => $sms_info]);
  50. } else {
  51. return app('json')->success(['status' => false]);
  52. }
  53. }
  54. /**
  55. * 获取套餐列表
  56. * @param string $type 套餐类型:sms,短信;query,物流查询;dump,电子面单;copy,产品复制
  57. * @return mixed
  58. */
  59. public function mealList(string $type)
  60. {
  61. $res = $this->services->user()->mealList($type);
  62. if ($res) {
  63. return app('json')->success($res);
  64. } else {
  65. return app('json')->fail('获取套餐列表失败');
  66. }
  67. }
  68. /**
  69. * 获取支付码
  70. * @return mixed
  71. */
  72. public function payMeal()
  73. {
  74. $data = $this->request->params(['meal_id', 'price', 'num', 'type', 'pay_type']);
  75. $openInfo = $this->services->user()->getUser();
  76. if (!$openInfo) app('json')->fail('获取支付码失败');
  77. switch ($data['type']) {
  78. case "sms" :
  79. if (!$openInfo['sms']['open']) return app('json')->fail('请先开通短信服务');
  80. break;
  81. case "query" :
  82. if (!$openInfo['query']['open']) return app('json')->fail('请先开通物流查询服务');
  83. break;
  84. case "dump" :
  85. if (!$openInfo['dump']['open']) return app('json')->fail('请先开通电子面单打印服务');
  86. break;
  87. case "copy" :
  88. if (!$openInfo['copy']['open']) return app('json')->fail('请先开通商品采集服务');
  89. break;
  90. }
  91. $this->validate($data, MealValidata::class);
  92. $res = $this->services->user()->payMeal($data);
  93. if ($res) {
  94. return app('json')->success($res);
  95. } else {
  96. return app('json')->fail('获取支付码失败');
  97. }
  98. }
  99. /**
  100. * 获取用户信息,用户信息内包含是否开通服务字段
  101. * @return mixed
  102. */
  103. public function getUserInfo()
  104. {
  105. return app('json')->success($this->services->user()->getUser());
  106. }
  107. /**
  108. * 查询使用记录
  109. * @return mixed
  110. */
  111. public function getRecord()
  112. {
  113. [$page, $limit] = $this->getPage();
  114. $data = $this->request->params(['type']);
  115. return app('json')->success($this->services->user()->record($page, $limit, $data['type']));
  116. }
  117. /**
  118. * 开通服务
  119. * @param string $type 套餐类型:sms,短信;query,物流查询;dump,电子面单;copy,产品复制
  120. * @return mixed
  121. */
  122. public function openServe()
  123. {
  124. $type = $this->request->param('type');
  125. switch ($type) {
  126. case 'sms': //短信呢
  127. $sign = $this->request->param('sign');
  128. if (!$sign) return app('json')->fail('请设置短信签名');
  129. $this->services->sms()->setSign($sign)->open();
  130. break;
  131. case 'query':
  132. $this->services->express()->open();
  133. break;
  134. case 'dump':
  135. $this->services->express()->open();
  136. break;
  137. case 'copy':
  138. $this->services->copy()->open();
  139. break;
  140. }
  141. return app('json')->success('开通成功');
  142. }
  143. /**
  144. * 修改密码
  145. * @return mixed
  146. */
  147. public function changePassword(CrmebServeValidata $validata)
  148. {
  149. $data = $this->request->params(['phone', 'account', 'password', 'verify_code']);
  150. $validata->check($data);
  151. $data['password'] = md5($data['password']);
  152. $this->services->user()->modify($data);
  153. Cache::delete('serve_account');
  154. return app('json')->success('修改成功');
  155. }
  156. /**
  157. * 修改手机号
  158. * @return mixed
  159. */
  160. public function updatePhone(CrmebServeValidata $validata)
  161. {
  162. $data = $this->request->params(['phone', 'account', 'verify_code']);
  163. $validata->scene('phone')->check($data);
  164. $this->services->user()->modifyPhone($data);
  165. Cache::delete('sms_account');
  166. return app('json')->success('修改成功');
  167. }
  168. /**
  169. * 电子面单配置信息
  170. * @return \think\response\Json
  171. * @author Qinii
  172. * @day 7/17/21
  173. */
  174. public function getConfig()
  175. {
  176. $params = [
  177. 'express_app_code' => systemConfig('express_app_code'),
  178. 'crmeb_serve_express' => systemConfig('crmeb_serve_express'),
  179. 'crmeb_serve_dump' => systemConfig('crmeb_serve_dump'),
  180. 'copy_product_status' => systemConfig('copy_product_status'),
  181. 'copy_product_apikey' => systemConfig('copy_product_apikey'),
  182. ];
  183. return app('json')->success($params);
  184. }
  185. /**
  186. * 电子面单配置信息 保存
  187. * @return \think\response\Json
  188. * @author Qinii
  189. * @day 7/17/21
  190. */
  191. public function setConfig()
  192. {
  193. $params = $this->request->params([
  194. 'express_app_code',
  195. 'crmeb_serve_express',
  196. 'crmeb_serve_dump',
  197. 'copy_product_status',
  198. 'copy_product_apikey'
  199. ]);
  200. app()->make(ConfigValueRepository::class)->setFormData($params, 0);
  201. return app('json')->success('保存成功');
  202. }
  203. /**
  204. * 购买记录
  205. * @return \think\response\Json
  206. * @author Qinii
  207. * @day 7/22/21
  208. */
  209. public function paylst()
  210. {
  211. [$page, $limit] = $this->getPage();
  212. $data = $this->services->user()->userBill($page, $limit);
  213. return app('json')->success($data);
  214. }
  215. /**
  216. * 商户购买记录
  217. * @return \think\response\Json
  218. * @author Qinii
  219. * @day 7/22/21
  220. */
  221. public function merPaylst()
  222. {
  223. [$page, $limit] = $this->getPage();
  224. $where = $this->request->params(['type', 'mer_id', 'date']);
  225. $data = app()->make(ServeOrderRepository::class)->getList($where, $page, $limit);
  226. return app('json')->success($data);
  227. }
  228. /**
  229. * 商户列表
  230. * @return \think\response\Json
  231. * @author Qinii
  232. * @day 7/22/21
  233. */
  234. public function merLst()
  235. {
  236. [$page, $limit] = $this->getPage();
  237. $where = $this->request->params(['mer_id', 'date']);
  238. $data = app()->make(MerchantRepository::class)->lst($where, $page, $limit);
  239. return app('json')->success($data);
  240. }
  241. }