123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- <?php
- namespace app\controller\admin\system\serve;
- //use app\validate\admin\serve\ServeValidata;
- //use app\services\system\config\SystemConfigServices;
- use app\common\repositories\system\config\ConfigValueRepository;
- use app\common\repositories\system\merchant\MerchantRepository;
- use app\common\repositories\system\serve\ServeOrderRepository;
- use app\validate\admin\ExpressValidata;
- use app\validate\admin\MealValidata;
- use ln\basic\BaseController;
- use ln\services\CrmebServeServices;
- use think\App;
- use think\facade\Cache;
- use app\validate\admin\CrmebServeValidata;
- /**
- * Class Serve
- * @package app\controller\admin\v1\serve
- */
- class Serve extends BaseController
- {
- protected $services;
- /**
- * Serve constructor.
- * @param App $app
- * @param ServeServices $services
- */
- public function __construct(App $app, CrmebServeServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
- /**
- * 检测登录
- * @return mixed
- */
- public function is_login()
- {
- $sms_info = Cache::get('serve_account');
- if ($sms_info) {
- return app('json')->success(['status' => true, 'info' => $sms_info]);
- } else {
- $account = systemConfig('sms_account');
- if (!$account) return app('json')->success(['status' => false]);
- $password = md5($account.systemConfig('sms_token'));
- $res = $this->services->user()->login($account, $password);
- if ($res) {
- Cache::set('serve_account', $account);
- $arr = [
- 'serve_account' => $account,
- 'serve_token' => $password,
- ];
- app()->make(ConfigValueRepository::class)->setFormData($arr, 0);
- $sms_info = Cache::get('serve_account');
- Cache::delete('sms_account');
- return app('json')->success(['status' => true, 'info' => $sms_info]);
- }
- return app('json')->success(['status' => false]);
- }
- }
- /**
- * 获取套餐列表
- * @param string $type 套餐类型:sms,短信;query,物流查询;dump,电子面单;copy,产品复制
- * @return mixed
- */
- public function mealList(string $type)
- {
- $res = $this->services->user()->mealList($type);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取套餐列表失败');
- }
- }
- /**
- * 获取支付码
- * @return mixed
- */
- public function payMeal()
- {
- $data = $this->request->params(['meal_id','price','num','type','pay_type']);
- $openInfo = $this->services->user()->getUser();
- if (!$openInfo) app('json')->fail('获取支付码失败');
- switch ($data['type']) {
- case "sms" :
- if (!$openInfo['sms']['open']) return app('json')->fail('请先开通短信服务');
- break;
- case "query" :
- if (!$openInfo['query']['open']) return app('json')->fail('请先开通物流查询服务');
- break;
- case "dump" :
- if (!$openInfo['dump']['open']) return app('json')->fail('请先开通电子面单打印服务');
- break;
- case "copy" :
- if (!$openInfo['copy']['open']) return app('json')->fail('请先开通商品采集服务');
- break;
- }
- $this->validate($data, MealValidata::class);
- $res = $this->services->user()->payMeal($data);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取支付码失败');
- }
- }
- /**
- * 获取用户信息,用户信息内包含是否开通服务字段
- * @return mixed
- */
- public function getUserInfo()
- {
- return app('json')->success($this->services->user()->getUser());
- }
- /**
- * 查询使用记录
- * @return mixed
- */
- public function getRecord()
- {
- [$page, $limit] = $this->getPage();
- $data = $this->request->params(['type']);
- return app('json')->success($this->services->user()->record($page, $limit, $data['type']));
- }
- /**
- * 开通服务
- * @param string $type 套餐类型:sms,短信;query,物流查询;dump,电子面单;copy,产品复制
- * @return mixed
- */
- public function openServe()
- {
- $type = $this->request->param('type');
- switch ($type)
- {
- case 'sms': //短信呢
- $sign = $this->request->param('sign');
- if(!$sign) return app('json')->fail('请设置短信签名');
- $this->services->sms()->setSign($sign)->open();
- break;
- case 'query':
- $this->services->express()->open();
- break;
- case 'dump':
- $this->services->express()->open();
- break;
- case 'copy':
- $this->services->copy()->open();
- break;
- }
- return app('json')->success('开通成功');
- }
- /**
- * 修改密码
- * @return mixed
- */
- public function changePassword(CrmebServeValidata $validata)
- {
- $data = $this->request->params(['phone','account','password','verify_code']);
- $validata->check($data);
- $data['password'] = md5($data['password']);
- $this->services->user()->modify($data);
- Cache::delete('serve_account');
- return app('json')->success('修改成功');
- }
- /**
- * 修改手机号
- * @return mixed
- */
- public function updatePhone(CrmebServeValidata $validata)
- {
- $data = $this->request->params(['phone','account','verify_code']);
- $validata->scene('phone')->check($data);
- $this->services->user()->modifyPhone($data);
- Cache::delete('sms_account');
- return app('json')->success('修改成功');
- }
- /**
- * TODO
- * @return \think\response\Json
- * @author Qinii
- * @day 7/17/21
- */
- public function getConfig()
- {
- $params = [
- 'express_app_code' => systemConfig('express_app_code'),
- 'crmeb_serve_express' => systemConfig('crmeb_serve_express'),
- 'crmeb_serve_dump' => systemConfig('crmeb_serve_dump'),
- 'copy_product_status' => systemConfig('copy_product_status'),
- 'copy_product_apikey' => systemConfig('copy_product_apikey'),
- ];
- return app('json')->success($params);
- }
- /**
- * TODO
- * @return \think\response\Json
- * @author Qinii
- * @day 7/17/21
- */
- public function setConfig()
- {
- $params = $this->request->params([
- 'express_app_code',
- 'crmeb_serve_express',
- 'crmeb_serve_dump',
- 'copy_product_status',
- 'copy_product_apikey'
- ]);
- app()->make(ConfigValueRepository::class)->setFormData($params,0);
- return app('json')->success('保存成功');
- }
- /**
- * TODO 购买记录
- * @return \think\response\Json
- * @author Qinii
- * @day 7/22/21
- */
- public function paylst()
- {
- [$page, $limit] = $this->getPage();
- $data = $this->services->user()->userBill($page, $limit);
- return app('json')->success($data);
- }
- /**
- * TODO
- * @return \think\response\Json
- * @author Qinii
- * @day 7/22/21
- */
- public function merPaylst()
- {
- [$page, $limit] = $this->getPage();
- $where = $this->request->params(['type','mer_id','date']);
- $data = app()->make(ServeOrderRepository::class)->getList($where,$page,$limit);
- return app('json')->success($data);
- }
- public function merLst()
- {
- [$page, $limit] = $this->getPage();
- $where = $this->request->params(['mer_id','date']);
- $data = app()->make(MerchantRepository::class)->lst($where, $page, $limit);
- return app('json')->success($data);
- }
- }
|