Serve.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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\serve;
  12. use app\controller\admin\AuthController;
  13. use app\services\message\sms\SmsAdminServices;
  14. use app\validate\admin\serve\ExpressValidate;
  15. use app\validate\admin\serve\MealValidate;
  16. use app\validate\admin\serve\ServeValidate;
  17. use app\services\system\config\SystemConfigServices;
  18. use crmeb\services\CacheService;
  19. use app\services\serve\ServeServices;
  20. use think\facade\App;
  21. /**
  22. * Class Serve
  23. * @package app\controller\admin\v1\serve
  24. */
  25. class Serve extends AuthController
  26. {
  27. /**
  28. * Serve constructor.
  29. * @param App $app
  30. * @param ServeServices $services
  31. */
  32. public function __construct(App $app, ServeServices $services)
  33. {
  34. parent::__construct($app);
  35. $this->services = $services;
  36. }
  37. /**
  38. * 检测登录
  39. * @return mixed
  40. */
  41. public function is_login()
  42. {
  43. $sms_info = CacheService::redisHandler()->get('sms_account');
  44. if ($sms_info) {
  45. return $this->success(['status' => true, 'info' => $sms_info]);
  46. } else {
  47. return $this->success(['status' => false]);
  48. }
  49. }
  50. /**
  51. * 获取套餐列表
  52. * @param string $type
  53. * @return mixed
  54. */
  55. public function mealList(string $type)
  56. {
  57. $res = $this->services->user()->mealList($type);
  58. if ($res) {
  59. return $this->success($res);
  60. } else {
  61. return $this->fail('获取套餐列表失败');
  62. }
  63. }
  64. /**
  65. * 获取支付码
  66. * @return mixed
  67. */
  68. public function payMeal()
  69. {
  70. $data = $this->request->postMore([
  71. ['meal_id', ''],
  72. ['price', ''],
  73. ['num', ''],
  74. ['type', ''],
  75. ['pay_type', ''],
  76. ]);
  77. $openInfo = $this->services->user()->getUser();
  78. if (!$openInfo) $this->fail('获取支付码失败');
  79. switch ($data['type']) {
  80. case "sms" :
  81. if (!$openInfo['sms']['open']) return $this->fail('请先开通短信服务');
  82. break;
  83. case "query" :
  84. if (!$openInfo['query']['open']) return $this->fail('请先开通物流查询服务');
  85. break;
  86. case "dump" :
  87. if (!$openInfo['dump']['open']) return $this->fail('请先开通电子面单打印服务');
  88. break;
  89. case "copy" :
  90. if (!$openInfo['copy']['open']) return $this->fail('请先开通商品采集服务');
  91. break;
  92. }
  93. $this->validate($data, MealValidate::class);
  94. $res = $this->services->user()->payMeal($data);
  95. if ($res) {
  96. return $this->success($res);
  97. } else {
  98. return $this->fail('获取支付码失败');
  99. }
  100. }
  101. /**
  102. * 开通打印电子面单
  103. * @return mixed
  104. */
  105. public function openExpress()
  106. {
  107. $data = $this->request->postMore([
  108. ['com', ''],
  109. ['temp_id', ''],
  110. ['to_name', ''],
  111. ['to_tel', ''],
  112. ['to_address', ''],
  113. ['siid', ''],
  114. ]);
  115. $this->validate($data, ExpressValidate::class);
  116. /** @var SystemConfigServices $systemConfigService */
  117. $systemConfigService = app()->make(SystemConfigServices::class);
  118. $systemConfigService->saveExpressInfo($data);
  119. $this->services->express()->open();
  120. return $this->success('开通成功');
  121. }
  122. /**
  123. * 获取用户信息,用户信息内包含是否开通服务字段
  124. * @return mixed
  125. */
  126. public function getUserInfo()
  127. {
  128. return $this->success($this->services->user()->getUser());
  129. }
  130. /**
  131. * 查询记录
  132. * @return mixed
  133. */
  134. public function getRecord()
  135. {
  136. [$page, $limit, $type] = $this->request->getMore([
  137. [['page', 'd'], 0],
  138. [['limit', 'd'], 10],
  139. [['type', 'd'], 0],
  140. ], true);
  141. return $this->success($this->services->user()->record($page, $limit, $type));
  142. }
  143. /**
  144. * 开通服务
  145. * @param int $type
  146. * @return mixed
  147. */
  148. public function openServe($type = 0)
  149. {
  150. if ($type) {
  151. $this->services->copy()->open();
  152. } else {
  153. $this->services->express()->open();
  154. }
  155. return $this->success('开通成功');
  156. }
  157. /**
  158. * 修改密码
  159. * @return mixed
  160. */
  161. public function modify(SmsAdminServices $services)
  162. {
  163. $data = $this->request->postMore([
  164. ['account', ''],
  165. ['password', ''],
  166. ['phone', ''],
  167. ['verify_code', ''],
  168. ]);
  169. $this->validate($data, ServeValidate::class);
  170. $data['password'] = md5($data['password']);
  171. $this->services->user()->modify($data);
  172. CacheService::redisHandler()->delete('sms_account');
  173. CacheService::redisHandler()->delete('sms_token');
  174. $services->updateSmsConfig('', '');
  175. return $this->success('修改成功');
  176. }
  177. /**
  178. * 修改手机号
  179. * @return mixed
  180. */
  181. public function updatePhone(SmsAdminServices $services)
  182. {
  183. $data = $this->request->postMore([
  184. ['account', ''],
  185. ['phone', ''],
  186. ['verify_code', ''],
  187. ]);
  188. $this->validate($data, ServeValidate::class, 'phone');
  189. $this->services->user()->modifyPhone($data);
  190. CacheService::redisHandler()->delete('sms_account');
  191. $services->updateSmsConfig('', '');
  192. return $this->success('修改成功');
  193. }
  194. }