【程序目录】优化程序逻辑

This commit is contained in:
吴昊天 2022-10-27 17:52:23 +08:00
parent b95303df59
commit 242922b009
29 changed files with 1694 additions and 1429 deletions

View File

@ -10,6 +10,7 @@
// +----------------------------------------------------------------------
namespace app\adminapi\controller;
use crmeb\services\CacheService;
use think\facade\App;
use crmeb\utils\Captcha;
use app\services\system\admin\SystemAdminServices;
@ -84,19 +85,14 @@ class Login extends AuthController
*/
public function login()
{
[$account, $password, $imgcode, $key, $captchaVerification, $captchaType] = $this->request->postMore([
[$account, $password, $key, $captchaVerification, $captchaType] = $this->request->postMore([
'account',
'pwd',
['imgcode', ''],
['key', ''],
['captchaVerification', ''],
['captchaType', '']
], true);
if (!app()->make(Captcha::class)->check($imgcode)) {
return app('json')->fail(400336);
}
if ($captchaVerification != '') {
try {
aj_captcha_check_two($captchaType, $captchaVerification);
@ -106,8 +102,17 @@ class Login extends AuthController
}
$this->validate(['account' => $account, 'pwd' => $password], \app\adminapi\validate\setting\SystemAdminValidata::class, 'get');
return app('json')->success($this->services->login($account, $password, 'admin', $key));
$result = $this->services->login($account, $password, 'admin', $key);
if (!$result) {
$num = CacheService::redisHandler()->get('login_captcha',1);
if ($num > 1) {
return app('json')->fail(400140, ['login_captcha' => 1]);
}
CacheService::redisHandler()->set('login_captcha', $num + 1, 60);
return app('json')->fail(400140, ['login_captcha' => 0]);
}
CacheService::redisHandler()->delete('login_captcha');
return app('json')->success($result);
}
/**

View File

@ -613,7 +613,7 @@ class UpgradeController
$uids = $storeOrderServices->getColumn([['id','in',array_column($list,'oid')]],'uid','id');
foreach ($list as $cart) {
$cartData['id'] = $cart['id'];
$cartData['uid'] = $uids[$cart['oid']];
$cartData['uid'] = $uids[$cart['oid']] ?? 0;
$allData[] = $cartData;
}
if ($allData) {

View File

@ -226,6 +226,9 @@ class AgentManage extends AuthController
$spreadInfo->save();
$userInfo->spread_uid = $spreadUid;
$userInfo->spread_time = time();
$userInfo->division_id = $spreadInfo->division_id;
$userInfo->agent_id = $spreadInfo->agent_id;
$userInfo->is_staff = $spreadInfo->is_staff;
$userInfo->save();
return app('json')->success(100001);
}

View File

@ -62,7 +62,7 @@ class StoreService extends AuthController
['data', '', '', 'time'],
['type', '', '', 'user_type'],
]);
[$list, $count] = $services->getWhereUserList($where, 'u.nickname,u.uid,u.avatar as headimgurl,w.subscribe,w.province,w.country,w.city,w.sex,w.user_type');
[$list, $count] = $services->getWhereUserList($where, 'u.nickname,u.uid,u.avatar as headimgurl,w.subscribe,w.province,w.country,w.city,w.sex,w.user_type,u.is_del');
return app('json')->success(compact('list', 'count'));
}

View File

@ -57,9 +57,9 @@ class SystemOutAccount extends AuthController
*/
public function set_status($id = '', $status = '')
{
if ($status == '' || $id == '') return $this->fail('缺少参数');
if ($status == '' || $id == '') return app('json')->fail(100100);
$this->services->update($id, ['status' => $status]);
return app('json')->success($status == 1 ? '开启成功' : '关闭成功');
return app('json')->success($status == 1 ? 100012 : 100013);
}
/**
@ -69,9 +69,9 @@ class SystemOutAccount extends AuthController
*/
public function delete($id)
{
if ($id == '') return $this->fail('缺少参数');
if ($id == '') return app('json')->fail(100100);
$this->services->update($id, ['is_del' => 1]);
return app('json')->success('删除成功!');
return app('json')->success(100002);
}
/**
@ -99,9 +99,9 @@ class SystemOutAccount extends AuthController
$data['add_time'] = time();
$data['rules'] = implode(',', $data['rules']);
if (!$this->services->save($data)) {
return app('json')->fail('添加失败');
return app('json')->fail(100006);
} else {
return app('json')->success('添加成功');
return app('json')->success(100000);
}
}
@ -131,26 +131,12 @@ class SystemOutAccount extends AuthController
$data['rules'] = implode(',', $data['rules']);
$res = $this->services->update($id, $data);
if (!$res) {
return app('json')->fail('修改失败');
return app('json')->fail(100006);
} else {
return app('json')->success('修改成功!');
return app('json')->success(100000);
}
}
/**
* 设置账号推送接口表单
* @param $id
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function outSetUpForm($id)
{
return app('json')->success($this->services->outSetUpForm($id));
}
/**
* 设置账号推送接口
* @param $id
@ -160,13 +146,17 @@ class SystemOutAccount extends AuthController
{
$data = $this->request->postMore([
['push_open', 0],
['push_account', ''],
['push_password', ''],
['push_token_url', ''],
['user_update_push', ''],
['order_create_push', ''],
['order_pay_push', ''],
['refund_create_push', ''],
['refund_cancel_push', ''],
]);
$this->services->outSetUpSave($id, $data);
return app('json')->success('修改成功');
return app('json')->success(100000);
}
/**
@ -181,4 +171,91 @@ class SystemOutAccount extends AuthController
{
return app('json')->success($service->outInterfaceList());
}
/**
* 保存接口文档
* @param $id
* @param OutInterfaceServices $service
* @return mixed
*/
public function saveInterface($id, OutInterfaceServices $service)
{
$data = $this->request->postMore([
['pid', 0], //上级id
['type', 0], //类型 0菜单 1接口
['name', ''], //名称
['describe', ''], //说明
['method', ''], //方法
['url', ''], //链接地址
['request_params', []], //请求参数
['return_params', []], //返回参数
['request_example', ''], //请求示例
['return_example', ''], //返回示例
['error_code', []] //错误码
]);
$service->saveInterface((int)$id, $data);
return app('json')->success(100000);
}
/**
* 对外接口文档
* @param $id
* @param OutInterfaceServices $service
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function interfaceInfo($id, OutInterfaceServices $service)
{
return app('json')->success($service->interfaceInfo($id));
}
/**
* 修改接口名称
* @param OutInterfaceServices $service
* @return mixed
*/
public function editInterfaceName(OutInterfaceServices $service)
{
$data = $this->request->postMore([
['id', 0], //上级id
['name', ''], //名称
]);
if (!$data['id'] || !$data['name']) {
return app('json')->success(100100);
}
$service->editInterfaceName($data);
return app('json')->success(100001);
}
/**
* 删除接口
* @param $id
* @param OutInterfaceServices $service
* @return mixed
*/
public function delInterface($id, OutInterfaceServices $service)
{
if (!$id) return app('json')->success(100100);
$service->delInterface($id);
return app('json')->success(100002);
}
/**
* 测试获取token接口
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function textOutUrl()
{
$data = $this->request->postMore([
['push_account', 0],
['push_password', 0],
['push_token_url', '']
]);
return app('json')->success('100014',$this->services->textOutUrl($data));
}
}

View File

@ -337,8 +337,11 @@ class User extends AuthController
/**
* 执行编辑其他
* @param int $id
* @param $id
* @return mixed
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
*/
public function update_other($id)
{
@ -356,23 +359,11 @@ class User extends AuthController
return app('json')->success($this->services->updateInfo($id, $data) ? 100001 : 100007);
}
/**
* 修改user表状态
*
* @return array
*/
public function set_status($status, $id)
{
// if ($status == '' || $id == 0) return app('json')->fail('参数错误');
// UserModel::where(['uid' => $id])->update(['status' => $status]);
return app('json')->success(100014);
}
/**
* 编辑会员信息
* @param $id
* @return mixed|\think\response\Json|void
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function edit($id)
{
@ -380,6 +371,14 @@ class User extends AuthController
return app('json')->success($this->services->edit($id));
}
/**
* 修改用户
* @param $id
* @return mixed
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
*/
public function update($id)
{
$data = $this->request->postMore([
@ -429,7 +428,7 @@ class User extends AuthController
/**
* 获取单个用户信息
* @param $id 用户id
* @param $id
* @return mixed
*/
public function oneUserInfo($id)

View File

@ -165,14 +165,24 @@ Route::group('setting', function () {
Route::post('system_out_account/update/:id', 'v1.setting.SystemOutAccount/update')->option(['real_name' => '对外接口账号修改']);
//设置账号是否禁用
Route::put('system_out_account/set_status/:id/:status', 'v1.setting.SystemOutAccount/set_status')->option(['real_name' => '设置账号是否禁用']);
//设置账号推送接口表单
Route::get('system_out_account/set_up/:id', 'v1.setting.SystemOutAccount/outSetUpForm')->option(['real_name' => '设置账号推送接口表单']);
//设置账号推送接口
Route::put('system_out_account/set_up/:id', 'v1.setting.SystemOutAccount/outSetUpSave')->option(['real_name' => '设置账号推送接口']);
//删除账号
Route::delete('system_out_account/:id', 'v1.setting.SystemOutAccount/delete')->option(['real_name' => '删除账号']);
//测试获取token接口
Route::post('system_out_account/text_out_url', 'v1.setting.SystemOutAccount/textOutUrl')->option(['real_name' => '测试获取token接口']);
//对外接口列表
Route::get('system_out_interface/list', 'v1.setting.SystemOutAccount/outInterfaceList')->option(['real_name' => '对外接口列表']);
//新增修改对外接口
Route::post('system_out_interface/save/:id', 'v1.setting.SystemOutAccount/saveInterface')->option(['real_name' => '新增修改对外接口']);
//对外接口信息
Route::get('system_out_interface/info/:id', 'v1.setting.SystemOutAccount/interfaceInfo')->option(['real_name' => '对外接口信息']);
//修改接口名称
Route::put('system_out_interface/edit_name', 'v1.setting.SystemOutAccount/editInterfaceName')->option(['real_name' => '修改接口名称']);
//删除接口
Route::delete('system_out_interface/del/:id', 'v1.setting.SystemOutAccount/delInterface')->option(['real_name' => '删除接口']);
/** 多语言 */
//语言国家列表

View File

@ -535,6 +535,7 @@ class StoreOrderController
['order_id', ''],
['time', ''],
['refund_type', 0],
['keywords', ''],
]);
$where['is_cancel'] = 0;
$data = $services->refundList($where)['list'];

View File

@ -40,7 +40,7 @@ class StoreCouponsController
$where = $request->getMore([
['type', 0],
['product_id', 0],
['num',0]
['num', 0]
]);
if ($request->getFromType() == 'pc') $where['type'] = -1;
return app('json')->success($this->services->getIssueCouponList($request->uid(), $where)['list']);
@ -88,8 +88,8 @@ class StoreCouponsController
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function order(Request $request, StoreCouponIssueServices $service, $cartId, $new)
public function order(Request $request, StoreCouponIssueServices $service, $cartId, $new, $shippingType)
{
return app('json')->success($service->beUsableCouponList((int)$request->uid(), $cartId, !!$new));
return app('json')->success($service->beUsableCouponList((int)$request->uid(), $cartId, !!$new, (int)$shippingType));
}
}

View File

@ -140,6 +140,9 @@ class UserController
* 静默绑定推广人
* @param Request $request
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function spread(Request $request)
{
@ -148,8 +151,8 @@ class UserController
['code', 0]
], true);
$uid = (int)$request->uid();
$this->services->spread($uid, (int)$spreadUid, $code);
return app('json')->success();
$res = $this->services->spread($uid, (int)$spreadUid, $code);
return app('json')->success($res);
}
/**

View File

@ -9,6 +9,7 @@ use app\services\activity\lottery\LuckLotteryRecordServices;
use app\services\activity\lottery\LuckLotteryServices;
use app\services\other\QrcodeServices;
use app\services\wechat\WechatServices;
use crmeb\services\CacheService;
class LuckLotteryController
{
@ -68,10 +69,18 @@ class LuckLotteryController
['id', 0],
['type', 0]
], true);
$uid = (int)$request->uid();
$key = 'lucklotter_limit_' . $uid;
if (CacheService::redisHandler()->get($key)) {
return app('json')->fail('您求的频率太过频繁,请稍后请求!');
}
CacheService::redisHandler()->set('lucklotter_limit_' . $uid, $uid, 1);
if ($type == 5 && request()->isWechat()) {
/** @var WechatServices $wechat */
$wechat = app()->make(WechatServices::class);
$subscribe = $wechat->get(['uid' => $request->uid(), 'subscribe' => 1]);
$subscribe = $wechat->get(['user_type' => 'wechat', 'uid' => $request->uid(), 'subscribe' => 1]);
if (!$subscribe) {
$url = '';
/** @var QrcodeServices $qrcodeService */
@ -83,7 +92,7 @@ class LuckLotteryController
if (!$id) {
return app('json')->fail(100100);
}
$uid = (int)$request->uid();
return app('json')->success($this->services->luckLottery($uid, $id));
}

View File

@ -11,6 +11,7 @@
// 应用公共文件
use crmeb\services\CacheService;
use crmeb\services\HttpService;
use Fastknife\Service\ClickWordCaptchaService;
use think\exception\ValidateException;
use crmeb\services\FormBuilder as Form;
@ -989,7 +990,7 @@ if (!function_exists('aj_captcha_check_two')) {
* @param string $pointJson
* @return bool
*/
function aj_captcha_check_two(string $captchaType, string $captchaVerification )
function aj_captcha_check_two(string $captchaType, string $captchaVerification)
{
aj_get_serevice($captchaType)->verificationByEncryptCode($captchaVerification);
return true;
@ -1030,3 +1031,24 @@ if (!function_exists('aj_get_serevice')) {
return $service;
}
}
if (!function_exists('out_push')) {
/**
* 默认数据推送
* @param string $pushUrl
* @param array $data
* @param string $tip
* @return bool
*/
function out_push(string $pushUrl, array $data, string $tip = ''): bool
{
$param = json_encode($data, JSON_UNESCAPED_UNICODE);
$res = HttpService::postRequest($pushUrl, $param, ['Content-Type:application/json', 'Content-Length:' . strlen($param)]);
$res = $res ? json_decode($res, true) : [];
if (!$res || !isset($res['code']) || $res['code'] != 0) {
\think\facade\Log::error(['msg' => $tip . '推送失败', 'data' => $res]);
return false;
}
return true;
}
}

View File

@ -4,6 +4,7 @@ namespace app\jobs;
use app\services\order\OutStoreOrderRefundServices;
use app\services\order\OutStoreOrderServices;
use app\services\user\UserServices;
use crmeb\basic\BaseJobs;
use crmeb\traits\QueueTrait;
use think\facade\Log;
@ -121,4 +122,30 @@ class OutPushJob extends BaseJobs
}
return true;
}
/**
* 余额,积分,佣金,经验变动推送
* @param array $data
* @param string $pushUrl
* @param int $step
* @return bool
*/
public function userUpdate(array $data, string $pushUrl, int $step = 0): bool
{
if ($step > 2) {
Log::error('用户变动推送失败');
return true;
}
try {
/** @var UserServices $services */
$services = app()->make(UserServices::class);
if (!$services->userUpdate($data, $pushUrl)) {
OutPushJob::dispatchSece(($step + 1) * 5, 'userUpdate', [$data, $pushUrl, $step + 1]);
}
} catch (\Exception $e) {
OutPushJob::dispatchSece(($step + 1) * 5, 'userUpdate', [$data, $pushUrl, $step + 1]);
}
return true;
}
}

View File

@ -5,27 +5,57 @@ namespace app\listener\out;
use app\jobs\OutPushJob;
use app\services\out\OutAccountServices;
use crmeb\interfaces\ListenerInterface;
use crmeb\services\CacheService;
use crmeb\services\HttpService;
use think\facade\Log;
class OutPush implements ListenerInterface
{
public function handle($event): void
{
[$type, $orderId] = $event;
[$type, $data] = $event;
/** @var OutAccountServices $outAccountServices */
$outAccountServices = app()->make(OutAccountServices::class);
$outAccountList = $outAccountServices->selectList(['is_del' => 0, 'status' => 1])->toArray();
foreach ($outAccountList as $item) {
if ($item['push_open'] == 1) {
$token = $this->getPushToken($item);
if ($type == 'order_create_push') {
OutPushJob::dispatchDo('orderCreate', [$orderId, $item['order_create_push']]);
OutPushJob::dispatchDo('orderCreate', [$data['order_id'], $item['order_create_push'] . '?pushToken=' . $token]);
} elseif ($type == 'order_pay_push') {
OutPushJob::dispatchDo('paySuccess', [$orderId, $item['order_pay_push']]);
}elseif($type == 'refund_create_push'){
OutPushJob::dispatchDo('refundCreate', [$orderId, $item['refund_create_push']]);
}elseif($type == 'refund_cancel_push'){
OutPushJob::dispatchDo('refundCancel', [$orderId, $item['refund_cancel_push']]);
OutPushJob::dispatchDo('paySuccess', [$data['order_id'], $item['order_pay_push'] . '?pushToken=' . $token]);
} elseif ($type == 'refund_create_push') {
OutPushJob::dispatchDo('refundCreate', [$data['order_id'], $item['refund_create_push'] . '?pushToken=' . $token]);
} elseif ($type == 'refund_cancel_push') {
OutPushJob::dispatchDo('refundCancel', [$data['order_id'], $item['refund_cancel_push'] . '?pushToken=' . $token]);
} elseif ($type == 'user_update_push') {
OutPushJob::dispatchDo('userUpdate', [$data, $item['user_update_push'] . '?pushToken=' . $token]);
}
}
}
}
/**
* 获取推送token
* @param array $info
* @return false|mixed
*/
public function getPushToken(array $info)
{
$token = CacheService::redisHandler()->get('pushToken' . $info['id']);
if (!$token) {
$param = json_encode(['push_account' => $info['push_account'], 'push_password' => $info['push_password']], JSON_UNESCAPED_UNICODE);
$res = HttpService::postRequest($info['push_token_url'], $param, ['Content-Type:application/json', 'Content-Length:' . strlen($param)]);
$res = $res ? json_decode($res, true) : [];
if (!$res || !isset($res['code']) || $res['code'] != 0) {
Log::error(['msg' => $info['title'] . ',获取token失败']);
return false;
}
CacheService::redisHandler()->set('pushToken' . $info['id'], $res['token'], $res['time']);
return $res['token'];
} else {
return $token;
}
}
}

View File

@ -171,4 +171,15 @@ class StoreOrderRefund extends BaseModel
'pay_time'
]);
}
/**
* @param $query
* @param $value
*/
public function searchKeywordsAttr($query, $value)
{
if ($value !== '') {
$query->where('order_id|refund_phone', 'like', '%' . $value . '%');
}
}
}

View File

@ -73,6 +73,8 @@ class OutAccount extends BaseModel
*/
public function searchIsDelAttr($query, $value)
{
$query->where('is_del', $value);
if ($value !== '') {
$query->where('is_del', $value);
}
}
}

View File

@ -8,7 +8,7 @@
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
declare (strict_types=1);
namespace app\services\activity\coupon;
@ -481,11 +481,11 @@ class StoreCouponIssueServices extends BaseServices
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function beUsableCouponList(int $uid, $cartId, bool $new)
public function beUsableCouponList(int $uid, $cartId, bool $new, int $shippingType = 1)
{
/** @var StoreCartServices $services */
$services = app()->make(StoreCartServices::class);
$cartGroup = $services->getUserProductCartListV1($uid, $cartId, $new);
$cartGroup = $services->getUserProductCartListV1($uid, $cartId, $new, [], $shippingType);
/** @var StoreCouponUserServices $coupServices */
$coupServices = app()->make(StoreCouponUserServices::class);
return $coupServices->getUsableCouponList($uid, $cartGroup);

View File

@ -8,7 +8,7 @@
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
declare (strict_types=1);
namespace app\services\message;
@ -51,40 +51,23 @@ class SystemNotificationServices extends BaseServices
return $this->dao->getOne($where);
}
/**
* 后台获取列表
* @param $where
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getNotList(array $where)
{
$industry = CacheService::get('wechat_industry', function () {
try {
$cache = (new Template('wechat'))->getIndustry();
if ($cache['primary_industry']['first_class'] != 'IT科技' || $cache['primary_industry']['second_class'] != '互联网|电子商务' || $cache['secondary_industry']['first_class'] != 'IT科技' || $cache['secondary_industry']['second_class'] != 'IT软件与服务') {
(new Template('wechat'))->setIndustry(1, 2);
}
return $cache->toArray();
} catch (\Exception $e) {
return $e->getMessage();
}
}, 0) ?: [];
!is_array($industry) && $industry = [];
$industry['primary_industry'] = isset($industry['primary_industry']) ? $industry['primary_industry']['first_class'] . ' | ' . $industry['primary_industry']['second_class'] : '未选择';
$industry['secondary_industry'] = isset($industry['secondary_industry']) ? $industry['secondary_industry']['first_class'] . ' | ' . $industry['secondary_industry']['second_class'] : '未选择';
$list = [
'industry' => $industry,
'list' => $this->dao->getList($where),
];
return $list;
// return $this->dao->getList($where);
return $this->dao->getList($where);
}
/**
* 获取单条数据
* @param array $where
* @return array
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
@ -129,6 +112,10 @@ class SystemNotificationServices extends BaseServices
/**
* 保存数据
* @param array $data
* @return bool|\crmeb\basic\BaseModel|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function saveData(array $data)
{

View File

@ -288,7 +288,7 @@ class OutStoreOrderRefundServices extends BaseServices
throw new AdminException(400118);
}
$refundInfo['order'] = $orderInfo->toArray();
return $this->push($pushUrl, $refundInfo, $id, '售后单');
return out_push($pushUrl, $refundInfo, '售后单');
}
/**
@ -307,26 +307,6 @@ class OutStoreOrderRefundServices extends BaseServices
throw new AdminException(400118);
}
$refundInfo['order'] = $orderInfo->toArray();
return $this->push($pushUrl, $refundInfo, $id, '取消售后单');
}
/**
* 发送请求
* @param string $pushUrl
* @param array $refundInfo
* @param int $id
* @param string $tip
* @return bool
*/
public function push(string $pushUrl, array $refundInfo, int $id, string $tip): bool
{
$param = json_encode($refundInfo, JSON_UNESCAPED_UNICODE);
$res = HttpService::postRequest($pushUrl, $param, ['Content-Type:application/json', 'Content-Length:' . strlen($param)]);
$res = $res ? json_decode($res, true) : [];
if (!$res || !isset($res['code']) || $res['code'] != 0) {
Log::error(['msg' => $tip . '推送失败', 'id' => $id, 'data' => $res]);
return false;
}
return true;
return out_push($pushUrl, $refundInfo, '取消售后单');
}
}

View File

@ -399,7 +399,7 @@ class OutStoreOrderServices extends BaseServices
public function orderCreatePush(int $id, string $pushUrl): bool
{
$orderInfo = $this->getInfo('', $id);
return $this->push($pushUrl, $orderInfo, $id, '订单');
return out_push($pushUrl, $orderInfo, '订单');
}
/**
@ -411,27 +411,6 @@ class OutStoreOrderServices extends BaseServices
public function paySuccessPush(int $id, string $pushUrl): bool
{
$orderInfo = $this->getInfo('', $id);
return $this->push($pushUrl, $orderInfo, $id, '订单支付');
return out_push($pushUrl, $orderInfo, '订单支付');
}
/**
* 发送请求
* @param string $pushUrl
* @param array $orderInfo
* @param int $id
* @param string $tip
* @return bool
*/
public function push(string $pushUrl, array $orderInfo, int $id, string $tip): bool
{
$param = json_encode($orderInfo, JSON_UNESCAPED_UNICODE);
$res = HttpService::postRequest($pushUrl, $param, ['Content-Type:application/json', 'Content-Length:' . strlen($param)]);
$res = $res ? json_decode($res, true) : [];
if (!$res || !isset($res['code']) || $res['code'] != 0) {
Log::error(['msg' => $tip . '推送失败', 'id' => $id, 'data' => $res]);
return false;
}
return true;
}
}

View File

@ -263,7 +263,7 @@ class StoreOrderCreateServices extends BaseServices
// 订单创建成功后置事件
event('order.orderCreateAfter', [$order, compact('cartInfo', 'priceData', 'addressId', 'cartIds', 'news'), $uid, $key, $combinationId, $seckillId, $bargainId]);
// 推送订单
event('out.outPush', ['order_create_push', (int)$order['id']]);
event('out.outPush', ['order_create_push', ['order_id' => (int)$order['id']]]);
return $order;
}

View File

@ -165,7 +165,9 @@ class StoreOrderRefundServices extends BaseServices
/** @var StoreOrderStatusServices $services */
$services = app()->make(StoreOrderStatusServices::class);
if (!$services->count(['oid' => $splitOrderInfo['id'], 'change_type' => 'refund_price'])) {
$this->regressionStock($splitOrderInfo);
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
$this->regressionStock($orderServices->get($splitOrderInfo['id']));
}
}
@ -996,7 +998,7 @@ class StoreOrderRefundServices extends BaseServices
//提醒推送
event('notice.notice', [['order' => $order], 'send_order_apply_refund']);
//推送订单
event('out.outPush', ['refund_create_push', (int)$order['id']]);
event('out.outPush', ['refund_create_push', ['order_id' => (int)$order['id']]]);
try {
ChannelService::instance()->send('NEW_REFUND_ORDER', ['order_id' => $order['order_id']]);
} catch (\Exception $e) {
@ -1253,7 +1255,7 @@ class StoreOrderRefundServices extends BaseServices
//售后订单取消后置事件
event('order.orderRefundCancelAfter', [$orderRefundInfo]);
// 推送订单
event('out.outPush', ['order_pay_push', (int)$orderRefundInfo['id']]);
event('out.outPush', ['refund_cancel_push', ['order_id' => (int)$orderRefundInfo['id']]]);
return true;
}

View File

@ -98,7 +98,7 @@ class StoreOrderSuccessServices extends BaseServices
//支付成功给客服发送消息
event('notice.notice', [$orderInfo, 'admin_pay_success_code']);
// 推送订单
event('out.outPush', ['order_pay_push', (int)$orderInfo['id']]);
event('out.outPush', ['order_pay_push', ['order_id' => (int)$orderInfo['id']]]);
$res = $res1 && $resPink;
return false !== $res;
}

View File

@ -13,9 +13,11 @@ namespace app\services\out;
use app\dao\out\OutAccountDao;
use app\services\BaseServices;
use crmeb\exceptions\AdminException;
use crmeb\exceptions\AuthException;
use crmeb\services\CacheService;
use crmeb\services\FormBuilder as Form;
use crmeb\services\HttpService;
use crmeb\utils\JwtAuth;
use Firebase\JWT\ExpiredException;
@ -113,6 +115,9 @@ class OutAccountServices extends BaseServices
* 获取列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where = [])
{
@ -134,6 +139,10 @@ class OutAccountServices extends BaseServices
* 刷新token
* @param string $token
* @return array
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function refresh(string $token): array
{
@ -237,26 +246,6 @@ class OutAccountServices extends BaseServices
return [$md5Token, $id, $type];
}
/**
* 设置账号推送接口表单
* @param $id
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function outSetUpForm($id)
{
$info = $this->dao->get($id);
$f[] = Form::radio('push_open', '推送开关', $info['push_open'] ?? 0)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
$f[] = Form::input('order_create_push', '订单创建推送', $info['order_create_push'] ?? '');
$f[] = Form::input('order_pay_push', '订单支付推送', $info['order_pay_push'] ?? '');
$f[] = Form::input('refund_create_push', '退款单创建推送', $info['refund_create_push'] ?? '');
$f[] = Form::input('refund_cancel_push', '退款单取消推送', $info['refund_cancel_push'] ?? '');
return create_form('设置推送', $f, $this->url('/setting/system_out_account/set_up/' . $id), 'PUT');
}
/**
* 设置账号推送接口
* @param $id
@ -267,4 +256,22 @@ class OutAccountServices extends BaseServices
{
return $this->dao->update($id, $data);
}
/**
* 测试获取token接口
* @param $data
* @return int[]|mixed
*/
public function textOutUrl($data)
{
if (!$data['push_account'] || !$data['push_password'] || !$data['push_token_url']) throw new AdminException(100100);
$param = ['push_account' => $data['push_account'], 'push_password' => $data['push_password']];
$res = HttpService::getRequest($data['push_token_url'], $param);
$res = $res ? json_decode($res, true) : ['status' => 400];
if ($res['status'] != 200) {
throw new AdminException(100015);
} else {
return $res['data'];
}
}
}

View File

@ -5,6 +5,7 @@ namespace app\services\out;
use app\dao\out\OutInterfaceDao;
use app\Request;
use app\services\BaseServices;
use crmeb\exceptions\AdminException;
use crmeb\exceptions\AuthException;
class OutInterfaceServices extends BaseServices
@ -44,7 +45,7 @@ class OutInterfaceServices extends BaseServices
*/
public function outInterfaceList(): array
{
$list = $this->dao->selectList([], '*,name as title')->toArray();
$list = $this->dao->selectList(['is_del' => 0], 'id,pid,method,type,name,name as title')->toArray();
$data = [];
foreach ($list as $key => $item) {
if ($item['pid'] == 0) {
@ -61,4 +62,68 @@ class OutInterfaceServices extends BaseServices
}
return $data;
}
/**
* 新增对外接口文档
* @param $id
* @param $data
* @return bool
*/
public function saveInterface($id, $data)
{
$data['request_params'] = json_encode($data['request_params']);
$data['return_params'] = json_encode($data['return_params']);
$data['error_code'] = json_encode($data['error_code']);
if ($id) {
$res = $this->dao->update($id, $data);
} else {
$res = $this->dao->save($data);
}
if (!$res) throw new AdminException(100006);
return true;
}
/**
* 对外接口文档
* @param $id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function interfaceInfo($id)
{
if (!$id) throw new AdminException(100100);
$info = $this->dao->get($id);
if (!$info) throw new AdminException(100026);
$info = $info->toArray();
$info['request_params'] = json_decode($info['request_params']);
$info['return_params'] = json_decode($info['return_params']);
$info['error_code'] = json_decode($info['error_code']);
return $info;
}
/**
* 修改接口名称
* @param $data
* @return bool
*/
public function editInterfaceName($data)
{
$res = $this->dao->update($data['id'], ['name' => $data['name']]);
if (!$res) throw new AdminException(100007);
return true;
}
/**
* 删除接口
* @param $id
* @return bool
*/
public function delInterface($id)
{
$res = $this->dao->update($id, ['is_del' => 1]);
if (!$res) throw new AdminException(100008);
return true;
}
}

View File

@ -19,10 +19,12 @@ use app\services\user\UserExtractServices;
use crmeb\exceptions\AdminException;
use app\dao\system\admin\SystemAdminDao;
use app\services\system\SystemMenusServices;
use crmeb\services\CacheService;
use crmeb\services\FormBuilder;
use crmeb\services\workerman\ChannelService;
use think\facade\Config;
use think\facade\Event;
use think\Model;
/**
* 管理员service
@ -54,7 +56,7 @@ class SystemAdminServices extends BaseServices
* 管理员登陆
* @param string $account
* @param string $password
* @return array|\think\Model
* @return array|bool|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
@ -62,15 +64,10 @@ class SystemAdminServices extends BaseServices
public function verifyLogin(string $account, string $password)
{
$adminInfo = $this->dao->accountByAdmin($account);
if (!$adminInfo) {
throw new AdminException(400594);
}
if (!$adminInfo || !password_verify($password, $adminInfo->pwd)) return false;
if (!$adminInfo->status) {
throw new AdminException(400595);
}
if (!password_verify($password, $adminInfo->pwd)) {
throw new AdminException(400140);
}
$adminInfo->last_time = time();
$adminInfo->last_ip = app('request')->ip();
$adminInfo->login_count++;
@ -83,7 +80,7 @@ class SystemAdminServices extends BaseServices
* 文件管理员登陆
* @param string $account
* @param string $password
* @return array|\think\Model
* @return array|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
@ -113,7 +110,7 @@ class SystemAdminServices extends BaseServices
* @param string $account
* @param string $password
* @param string $type
* @return array
* @return array|bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
@ -121,6 +118,7 @@ class SystemAdminServices extends BaseServices
public function login(string $account, string $password, string $type, string $key = '')
{
$adminInfo = $this->verifyLogin($account, $password);
if (!$adminInfo) return false;
$tokenInfo = $this->createToken($adminInfo->id, $type, $adminInfo->pwd);
/** @var SystemMenusServices $services */
$services = app()->make(SystemMenusServices::class);
@ -157,7 +155,7 @@ class SystemAdminServices extends BaseServices
{
$key = uniqid();
event('admin.info', [$key]);
return [
$data = [
'slide' => sys_data('admin_login_slide') ?? [],
'logo_square' => sys_config('site_logo_square'),//透明
'logo_rectangle' => sys_config('site_logo'),//方形
@ -165,8 +163,13 @@ class SystemAdminServices extends BaseServices
'site_name' => sys_config('site_name'),
'copyright' => sys_config('nncnL_crmeb_copyright', ''),
'version' => get_crmeb_version(),
'key' => $key
'key' => $key,
'login_captcha' => 0
];
if (CacheService::redisHandler()->get('login_captcha', 1) > 1) {
$data['login_captcha'] = 1;
}
return $data;
}
/**

View File

@ -61,6 +61,7 @@ class LangTypeServices extends BaseServices
{
if ($data['id']) {
$this->dao->update($data['id'], $data);
$id = $data['id'];
} else {
unset($data['id']);
$res = $this->dao->save($data);
@ -77,9 +78,10 @@ class LangTypeServices extends BaseServices
} else {
throw new AdminException(100006);
}
$id = $res->id;
}
//设置默认
if ($data['is_default'] == 1) $this->dao->update([['id', '<>', $res->id]], ['is_default' => 0]);
if ($data['is_default'] == 1) $this->dao->update([['id', '<>', $id]], ['is_default' => 0]);
return true;
}

View File

@ -759,8 +759,12 @@ class UserServices extends BaseServices
/**
* 修改提交处理
* @param $id
* @return mixed
* @param int $id
* @param array $data
* @return bool
* @throws Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
*/
public function updateInfo(int $id, array $data)
{
@ -786,6 +790,7 @@ class UserServices extends BaseServices
}
$res1 = $userMoneyServices->income('system_sub', $user['uid'], $data['money'], $edit['now_money'], $data['adminId'] ?? 0);
}
event('out.outPush', ['user_update_push', ['uid' => $id, 'type' => 'money', 'value' => $data['money_status'] == 2 ? -floatval($data['money']) : $data['money']]]);
} else {
$res1 = true;
}
@ -806,6 +811,7 @@ class UserServices extends BaseServices
$integral_data['mark'] = '系统扣除了' . floatval($data['integration']) . '积分';
$res2 = $userBill->expendIntegral($user['uid'], 'system_sub', $integral_data);
}
event('out.outPush', ['user_update_push', ['uid' => $id, 'type' => 'point', 'value' => $data['integration_status'] == 2 ? -intval($data['integration']) : $data['integration']]]);
} else {
$res2 = true;
}
@ -1583,8 +1589,13 @@ class UserServices extends BaseServices
/**
* 静默绑定推广人
* @param Request $request
* @return mixed
* @param int $uid
* @param int $spreadUid
* @param $code
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function spread(int $uid, int $spreadUid, $code)
{
@ -1599,6 +1610,7 @@ class UserServices extends BaseServices
$spreadUid = $info['third_id'];
}
}
if ($spreadUid == 0) return '不绑定';
$userSpreadUid = $this->dao->value(['uid' => $spreadUid], 'spread_uid');
//记录好友关系
if ($spreadUid && $uid && $spreadUid != $uid) {
@ -1609,26 +1621,38 @@ class UserServices extends BaseServices
'friends_uid' => $spreadUid,
]);
}
//记录上下级关系
if (!$userInfo['spread_uid'] && $spreadUid != $uid && $userSpreadUid != $userInfo['uid']) {
if ((sys_config('brokerage_bindind') == 2 && $userInfo['add_time'] == $userInfo['last_time']) || sys_config('brokerage_bindind') == 1) {
$spreadInfo = $this->dao->get($spreadUid);
$data = [];
$data['spread_uid'] = $spreadUid;
$data['spread_time'] = time();
$data['division_id'] = $spreadInfo['division_id'];
$data['agent_id'] = $spreadInfo['agent_id'];
$data['staff_id'] = $spreadInfo['staff_id'];
if (!$this->dao->update($uid, $data, 'uid')) {
throw new ApiException(410288);
$check = false;
if (sys_config('brokerage_bindind') == 1) {
if (sys_config('store_brokerage_binding_status') == 1) {
if (!$userInfo['spread_uid']) {
$check = true;
}
/** @var UserBillServices $userBill */
$userBill = app()->make(UserBillServices::class);
//邀请新用户增加经验
$userBill->inviteUserIncExp((int)$spreadUid);
} elseif (sys_config('store_brokerage_binding_status') == 2 && (($userInfo['spread_time'] + (sys_config('store_brokerage_binding_time') * 86400)) < time())) {
$check = true;
} elseif (sys_config('store_brokerage_binding_status') == 3) {
$check = true;
}
} elseif (sys_config('brokerage_bindind') == 2) {
if ($userInfo['add_time'] == $userInfo['last_time']) {
$check = true;
}
}
return true;
if ($userInfo['uid'] == $userSpreadUid || $userInfo['spread_uid'] == $spreadUid) $check = false;
if ($check) {
$spreadInfo = $this->dao->get($spreadUid);
$data = [];
$data['spread_uid'] = $spreadUid;
$data['spread_time'] = time();
$data['division_id'] = $spreadInfo['division_id'];
$data['agent_id'] = $spreadInfo['agent_id'];
$data['staff_id'] = $spreadInfo['staff_id'];
if (!$this->dao->update($uid, $data, 'uid')) {
throw new ApiException(410288);
}
return '绑定上级成功,上级uid为' . $spreadUid;
} else {
return '不绑定';
}
}
/**
@ -2129,7 +2153,7 @@ class UserServices extends BaseServices
/** @var UserMoneyServices $userMoneyServices */
$userMoneyServices = app()->make(UserMoneyServices::class);
$edit['now_money'] = bcadd($user['now_money'], $reward_money, 2);
$res1 = $userMoneyServices->income('register_system_add', $user['uid'], $reward_money, $edit['now_money'], 1);
$res1 = $userMoneyServices->income('register_system_add', $user['uid'], $reward_money, $edit['now_money'], 1);
} else {
$res1 = true;
}
@ -2152,4 +2176,15 @@ class UserServices extends BaseServices
return true;
else throw new AdminException(100007);
}
/**
* 推送用户信息
* @param $data
* @param $pushUrl
* @return bool
*/
public function userUpdate($data, $pushUrl)
{
return out_push($pushUrl, $data, '更新用户信息');
}
}

File diff suppressed because one or more lines are too long