Serve.php 8.0 KB

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