commit
8e59dc334c
@ -55,6 +55,11 @@ class SpuDao extends BaseDao
|
||||
if(isset($where['order']) && $where['order'] === 'none'){
|
||||
$order = '';
|
||||
}
|
||||
|
||||
if(isset($where['order_remark']) && $where['order_remark'] === 'none'){
|
||||
$order = '';
|
||||
}
|
||||
|
||||
$query = Spu::getDB()->alias('S')->join('StoreProduct P','S.product_id = P.product_id', 'left');
|
||||
$query->when(isset($where['is_del']) && $where['is_del'] !== '',function($query)use($where){
|
||||
$query->where('P.is_del',$where['is_del']);
|
||||
@ -90,9 +95,9 @@ class SpuDao extends BaseDao
|
||||
->when(isset($where['is_trader']) && $where['is_trader'] !== '',function($query)use($where){
|
||||
$merId = app()->make(MerchantRepository::class)->search([
|
||||
'is_trader' => $where['is_trader'],
|
||||
'status' => 1,
|
||||
'mer_state' => 1,
|
||||
'is_del' => 1,
|
||||
'status' => 1,//状态正常
|
||||
'mer_state' => 1,//商户开启
|
||||
'is_del' => 1,//
|
||||
])->column('mer_id');
|
||||
|
||||
$query->whereIn('P.mer_id',$merId);
|
||||
|
@ -52,7 +52,7 @@ class StoreOrderOther extends BaseModel
|
||||
|
||||
public function refundOrder()
|
||||
{
|
||||
return $this->hasMany(StoreRefundOrder::class,'order_id','order_id');
|
||||
return $this->hasMany(StoreRefundOrderOther::class,'order_id','order_id');
|
||||
}
|
||||
|
||||
public function orderStatus()
|
||||
|
@ -319,7 +319,7 @@ class Merchant extends BaseModel
|
||||
|
||||
public function promoter()
|
||||
{
|
||||
return User::where('uid', $this->uid)->value('spread_uid');
|
||||
return User::where('uid', $this->uid)->field('spread_uid as uid,nickname')->find();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -260,14 +260,14 @@ class StoreOrderRepository extends BaseRepository
|
||||
$groupOrder->append(['orderList.orderProduct']);
|
||||
$flag = true;
|
||||
$profitsharing = [];
|
||||
$userMerchantRepository = app()->make(UserMerchantRepository::class);
|
||||
$storeOrderProfitsharingRepository = app()->make(StoreOrderProfitsharingRepository::class);
|
||||
$userMerchantRepository = app()->make(UserMerchantRepository::class);//商户用户表
|
||||
$storeOrderProfitsharingRepository = app()->make(StoreOrderProfitsharingRepository::class);//分账
|
||||
$uid = $groupOrder->uid;
|
||||
// $isVipCoupon = app()->make(StoreGroupOrderRepository::class)->isVipCoupon($groupOrder);
|
||||
//订单记录
|
||||
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
|
||||
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);//订单操作
|
||||
$svipDiscount = 0;
|
||||
$financeDao = new FinancialDao();
|
||||
$financeDao = new FinancialDao(); //商户财务申请提现
|
||||
foreach ($groupOrder->orderList as $_k => $order) {
|
||||
$isPickupCard = $order->source == 999;
|
||||
(new StoreActivityDao())->saveOrderProduct(2, $order);
|
||||
@ -280,7 +280,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
$presell = false;
|
||||
//todo 等待付尾款
|
||||
if ($order->activity_type == 2) {
|
||||
$_make = app()->make(ProductPresellSkuRepository::class);
|
||||
$_make = app()->make(ProductPresellSkuRepository::class);//库存
|
||||
if ($order->orderProduct[0]['cart_info']['productPresell']['presell_type'] == 2) {
|
||||
$order->status = 10;
|
||||
$presell = true;
|
||||
@ -291,7 +291,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
} else if ($order->activity_type == 4) {
|
||||
$order->status = 9;
|
||||
$order->save();
|
||||
$group_buying_id = app()->make(ProductGroupBuyingRepository::class)->create(
|
||||
$group_buying_id = app()->make(ProductGroupBuyingRepository::class)->create( //平团
|
||||
$groupOrder->user,
|
||||
$order->orderProduct[0]['cart_info']['activeSku']['product_group_id'],
|
||||
$order->orderProduct[0]['activity_id'],
|
||||
@ -333,7 +333,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
|
||||
foreach ($order->orderProduct as $product) {
|
||||
if ($flag && $product['cart_info']['product']['is_gift_bag']) {
|
||||
app()->make(UserRepository::class)->promoter($order->uid);
|
||||
app()->make(UserRepository::class)->promoter($order->uid); //推广
|
||||
$flag = false;
|
||||
}
|
||||
}
|
||||
@ -360,10 +360,12 @@ class StoreOrderRepository extends BaseRepository
|
||||
$promoter = $order->merchant->promoter();
|
||||
$promoterCommission = bcmul($orderValidAmount, 0.003, 2);
|
||||
if (!empty($promoter) && $promoterCommission > 0) {
|
||||
$financeDao->user = $promoter;
|
||||
$financeDao->platformOut($promoterCommission, 'commission_to_promoter');
|
||||
}
|
||||
|
||||
// 平台收入手续费
|
||||
$financeDao->user = $groupOrder->user;
|
||||
$commission_rate = bcdiv((string)$order['commission_rate'],'100',6);
|
||||
$platformCommission = bcmul($orderValidAmount, (string)$commission_rate, 2);
|
||||
if ($commission_rate > 0 && $platformCommission > 0) {
|
||||
@ -376,7 +378,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
|
||||
if ($orderValidAmount > 0) {
|
||||
/** @var MerchantRepository $merchantRepo */
|
||||
$merchantRepo = app()->make(MerchantRepository::class);
|
||||
$merchantRepo = app()->make(MerchantRepository::class);//商户
|
||||
$merchantRepo->merId = $order['mer_id'];
|
||||
$merchantRepo->forceMargin = false;
|
||||
[$orderValidAmount, $financeDao] = $merchantRepo->deductDeposit($orderValidAmount, $order, $financeDao);
|
||||
@ -794,20 +796,22 @@ class StoreOrderRepository extends BaseRepository
|
||||
}
|
||||
|
||||
$promoterCommission = FinancialRecord::where('order_id', $order['order_id'])
|
||||
->where('financial_type', 'promoter_commission')
|
||||
->column('user_id,number');
|
||||
->where('financial_type', 'commission_to_promoter')
|
||||
->field('user_id,number')
|
||||
->find();
|
||||
if (!empty($promoterCommission)) {
|
||||
$userBillRepository->incBill($promoterCommission['user_id'], 'brokerage', 'order_one', [
|
||||
'link_id' => $order['order_id'],
|
||||
'status' => 0,
|
||||
'status' => 1,
|
||||
'title' => '获得推广佣金',
|
||||
'number' => $promoterCommission['number'],
|
||||
'mark' => $order->merchant['mer_name'] . '成功销售' . floatval($order['pay_price']) . '元,奖励推广佣金' . floatval($promoterCommission['number']),
|
||||
'balance' => 0
|
||||
]);
|
||||
|
||||
$balance = bcadd($user->now_money, $promoterCommission['number'], 2);
|
||||
$user->save(['now_money' => $balance]);
|
||||
$promoter = User::where('uid', $promoterCommission['user_id'])->find();
|
||||
$balance = bcadd($promoter->now_money, $promoterCommission['number'], 2);
|
||||
$promoter->save(['now_money' => $balance]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,10 +237,12 @@ class StoreOtherOrderRepository extends BaseRepository
|
||||
$promoter = $order->merchant->promoter();
|
||||
$promoterCommission = bcmul($orderValidAmount, 0.003, 2);
|
||||
if (!empty($promoter) && $promoterCommission > 0) {
|
||||
$financeDao->user = $promoter;
|
||||
$financeDao->platformOut($promoterCommission, 'commission_to_promoter');
|
||||
}
|
||||
|
||||
// 平台收入手续费
|
||||
$financeDao->user = $groupOrder->user;
|
||||
$commission_rate = bcdiv((string)$order['commission_rate'],'100',6);
|
||||
$platformCommission = bcmul($orderValidAmount, (string)$commission_rate, 2);
|
||||
if ($commission_rate > 0 && $platformCommission > 0) {
|
||||
@ -1082,6 +1084,9 @@ class StoreOtherOrderRepository extends BaseRepository
|
||||
'spread' => function ($query) {
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
'merchant' => function ($query) {
|
||||
$query->field('mer_id,mer_name');
|
||||
},
|
||||
]
|
||||
);
|
||||
if (!$res) throw new ValidateException('数据不存在');
|
||||
|
@ -417,6 +417,8 @@ class ProductRepository extends BaseRepository
|
||||
$data['cost'] = $settleParams['data']['cost'];
|
||||
$data['stock'] = $settleParams['data']['stock'];
|
||||
$data['svip_price'] = $settleParams['data']['svip_price'];
|
||||
|
||||
$data['update_time'] = date('Y-m-d H:i:s',time());
|
||||
}
|
||||
$res = $this->dao->update($id, $data);
|
||||
|
||||
|
@ -154,6 +154,19 @@ class SpuRepository extends BaseRepository
|
||||
if (!empty($this->orderField)) {
|
||||
$this->dao->orderField = $this->orderField;
|
||||
}
|
||||
//取消数量排序
|
||||
$where['order_remark'] = "none";
|
||||
$queryCount = $this->dao->search($where);
|
||||
// $queryCount->with([
|
||||
// 'merchant' => function ($queryCount) {
|
||||
// $queryCount->field($this->merchantFiled)->with(['type_names', 'street_names']);
|
||||
// },
|
||||
// 'issetCoupon',
|
||||
// 'product.attrValue',
|
||||
// ]);
|
||||
unset($where['order_remark']);
|
||||
$count = $queryCount->count();
|
||||
|
||||
$query = $this->dao->search($where);
|
||||
|
||||
$query->with([
|
||||
@ -164,7 +177,7 @@ class SpuRepository extends BaseRepository
|
||||
'product.attrValue',
|
||||
]);
|
||||
$productMake = app()->make(ProductRepository::class);
|
||||
$count = $query->count();
|
||||
// $count = $query->count();
|
||||
if ($limit == 0) {
|
||||
$list = $query->setOption('field', [])->field($this->productFiled)->select()
|
||||
->each(function ($item) use ($is_sku, $productMake, $userInfo,$where) {
|
||||
|
@ -37,6 +37,13 @@ class FinancialRecordRepository extends BaseRepository
|
||||
,'commission_to_cloud_warehouse','commission_to_cloud_warehouse_refund', 'commission_to_store', 'commission_to_courier', 'commission_to_promoter', 'commission_to_store_refund', 'commission_to_courier_refund', 'commission_to_promoter_refund', 'auto_margin', 'auto_margin_refund', 'supply_chain', 'supply_chain_refund', 'platform_consumption', 'platform_consumption_refund', 'merchant_order', 'merchant_order_refund'
|
||||
];
|
||||
|
||||
public $commonFinancialMixType = [
|
||||
'order', 'order_presell', 'order_refund', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon',
|
||||
'order_svip_coupon','commission_to_service_team','commission_to_service_team_refund','commission_to_platform','commission_to_platform_refund','commission_to_village','commission_to_village_refund','commission_to_town','commission_to_town_refund'
|
||||
,'commission_to_entry_merchant','commission_to_entry_merchant_refund'
|
||||
,'commission_to_cloud_warehouse','commission_to_cloud_warehouse_refund', 'commission_to_courier', 'commission_to_store_refund', 'commission_to_courier_refund', 'commission_to_promoter_refund', 'auto_margin','supply_chain', 'supply_chain_refund', 'platform_consumption', 'platform_consumption_refund', 'merchant_order', 'merchant_order_refund'
|
||||
];
|
||||
|
||||
const TYPE_CN_MAP = [
|
||||
'order' => '订单支付',
|
||||
'order_presell' => '预售订单(定金)',
|
||||
@ -414,7 +421,8 @@ class FinancialRecordRepository extends BaseRepository
|
||||
//日
|
||||
if ($where['type'] == 1) {
|
||||
$field = Db::raw('from_unixtime(unix_timestamp(create_time),\'%Y-%m-%d\') as time');
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//月
|
||||
if (!empty($where['date'])) {
|
||||
list($startTime, $endTime) = explode('-', $where['date']);
|
||||
@ -425,12 +433,13 @@ class FinancialRecordRepository extends BaseRepository
|
||||
}
|
||||
$field = Db::raw('from_unixtime(unix_timestamp(create_time),\'%Y-%m\') as time');
|
||||
}
|
||||
$make = app()->make(UserBillRepository::class);
|
||||
// $make = app()->make(UserBillRepository::class);
|
||||
|
||||
$query = $this->dao->search($where)->field($field)->group("time")->order('create_time DESC');
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->select()->each(function ($item) use ($where, $merchant) {
|
||||
$key = $where['is_mer'] ? $where['is_mer'] . '_financial_record_list_' . $item['time'] : 'sys_financial_record_list_' . $item['time'];
|
||||
|
||||
if (($where['type'] == 1 && ($item['time'] == date('Y-m-d', time()))) || ($where['type'] == 2 && ($item['time'] == date('Y-m', time())))) {
|
||||
$income = ($this->countIncome($where['type'], $where, $item['time'],$merchant))['number'];
|
||||
$expend = ($this->countExpend($where['type'], $where, $item['time'],$merchant))['number'];
|
||||
@ -440,7 +449,7 @@ class FinancialRecordRepository extends BaseRepository
|
||||
'charge' => bcsub($income, $expend, 2),
|
||||
];
|
||||
} else {
|
||||
if (!$ret = Cache::get($key)) {
|
||||
if (empty(Cache::get($key))) {
|
||||
$income = ($this->countIncome($where['type'], $where, $item['time'],$merchant))['number'];
|
||||
$expend = ($this->countExpend($where['type'], $where, $item['time'],$merchant))['number'];
|
||||
$ret = [
|
||||
@ -449,6 +458,8 @@ class FinancialRecordRepository extends BaseRepository
|
||||
'charge' => bcsub($income, $expend, 2),
|
||||
];
|
||||
Cache::tag('system')->set($key, $ret, 24 * 3600);
|
||||
} else{
|
||||
$ret = Cache::get($key);
|
||||
}
|
||||
}
|
||||
$item['income'] = $ret['income'];
|
||||
@ -613,7 +624,7 @@ class FinancialRecordRepository extends BaseRepository
|
||||
'commission_to_courier_refund', 'supply_chain_refund', 'auto_margin', 'platform_consumption_refund'];
|
||||
}
|
||||
if ($merchant){
|
||||
switch ($merchant['type_id']) {
|
||||
switch ($merchant['type_id']) {//21?
|
||||
case 16:
|
||||
$financialType1 = ['commission_to_town'];
|
||||
break;
|
||||
@ -633,7 +644,9 @@ class FinancialRecordRepository extends BaseRepository
|
||||
$financialType1 = [];
|
||||
}
|
||||
|
||||
$financialType = array_merge($financialType, $financialType1);
|
||||
|
||||
|
||||
$financialType = array_merge($financialType, $financialType1,$this->commonFinancialMixType);
|
||||
}
|
||||
[$data['count_order'], $data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType);
|
||||
if (!empty($financialType1)){
|
||||
|
@ -16,6 +16,7 @@ use app\common\model\system\merchant\Merchant;
|
||||
use app\common\model\system\merchant\MerchantCategory;
|
||||
use app\common\model\system\merchant\MerchantIntention;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\system\config\ConfigValueRepository;
|
||||
use crmeb\jobs\SendSmsJob;
|
||||
use crmeb\services\SmsService;
|
||||
use FormBuilder\Factory\Elm;
|
||||
@ -182,6 +183,11 @@ class MerchantIntentionRepository extends BaseRepository
|
||||
if ($data['status'] == 1) {
|
||||
if ($create) {
|
||||
$merchant = app()->make(MerchantRepository::class)->createMerchant($merData);
|
||||
if (!empty($intention['images'])) {
|
||||
app()->make(ConfigValueRepository::class)->setFormData([
|
||||
'mer_certificate' => $intention['images']
|
||||
], $merchant->mer_id);
|
||||
}
|
||||
$data['mer_id'] = $merchant->mer_id;
|
||||
$data['uid'] = $intention['uid'];
|
||||
$data['reg_admin_id'] = $autoCreate ? 0: $merchant['merchant_admin']['merchant_admin_id'];
|
||||
|
@ -149,9 +149,22 @@ class Financial extends BaseController
|
||||
{
|
||||
$where = $this->request->params(['date', 'status', 'financial_type', 'financial_status', 'keyword', 'is_trader', 'mer_id']);
|
||||
[$page, $limit] = $this->getPage();
|
||||
$data = app()->make(ExcelService::class)->financialLog($where,$page,$limit);
|
||||
/** @var ExcelService $make */
|
||||
$make = app()->make(ExcelService::class);
|
||||
$data = $make->financialLog($where,$page,$limit);
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
|
||||
public function billExport()
|
||||
{
|
||||
$where = $this->request->params(['date', 'status', 'financial_type', 'financial_status', 'keyword', 'is_trader', 'mer_id']);
|
||||
[$page, $limit] = $this->getPage();
|
||||
$data = app()->make(ExcelService::class)->withdrawalBill($where,$page,$limit);
|
||||
return app('json')->success($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,6 +14,18 @@
|
||||
namespace app\controller\api;
|
||||
|
||||
|
||||
use app\common\model\store\consumption\StoreConsumptionDetail;
|
||||
use app\common\model\store\consumption\StoreConsumptionUser;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreOrderOther;
|
||||
use app\common\model\store\order\StoreOrderProduct;
|
||||
use app\common\model\store\order\StoreOrderStatus;
|
||||
use app\common\model\store\order\StoreRefundOrder;
|
||||
use app\common\model\system\merchant\FinancialRecord;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\model\user\UserBill;
|
||||
use app\common\model\user\UserRecharge;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\store\order\StoreRefundOrderRepository;
|
||||
use app\common\repositories\system\notice\SystemNoticeConfigRepository;
|
||||
@ -41,6 +53,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\db\Query;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
@ -122,7 +135,7 @@ class Auth extends BaseController
|
||||
$destination = public_path('uploads').'img/' . $filename; // 目标路径
|
||||
$pict_url= $url.'/uploads/img/'.$filename;
|
||||
file_put_contents($destination, file_get_contents($res->pict_url));
|
||||
|
||||
|
||||
if($resp && isset($resp->small_images) && isset($resp->small_images->string)){
|
||||
foreach($resp->small_images->string as $k=>$v){
|
||||
$filename = basename($v); // 获取文件名
|
||||
@ -197,13 +210,13 @@ class Auth extends BaseController
|
||||
function convertUrlQuery($query)
|
||||
{
|
||||
$queryParts = explode('&', $query);
|
||||
|
||||
|
||||
$params = array();
|
||||
foreach ($queryParts as $param) {
|
||||
$item = explode('=', $param);
|
||||
$params[$item[0]] = $item[1];
|
||||
}
|
||||
|
||||
|
||||
return $params;
|
||||
}
|
||||
public function dotest()
|
||||
@ -378,8 +391,9 @@ class Auth extends BaseController
|
||||
}else{
|
||||
$data['mer_info'] =$mer_arr;
|
||||
}
|
||||
$typCode = Db::name('merchant_type')->where('mer_type_id', $mer_arr['type_id'] ?? 0)->value('type_code');
|
||||
$data['mer_info']['type_code'] = $typCode;
|
||||
$merType = Db::name('merchant_type')->where('mer_type_id', $mer_arr['type_id'] ?? 0)->field('type_code,type_name')->find();
|
||||
$data['mer_info']['type_code'] = $merType['type_code'];
|
||||
$data['mer_info']['type_name'] = $merType['type_name'];
|
||||
$data['mer_info']['setting_status'] = 0;
|
||||
if (($mer_arr['update_time'] ?? '') > ($mer_arr['create_time'] ?? '')) {
|
||||
$data['mer_info']['setting_status'] = 1;
|
||||
@ -874,9 +888,10 @@ class Auth extends BaseController
|
||||
throw new ValidateException('授权失败[003]');
|
||||
return $user;
|
||||
} else if ($auth['type'] === 'app_wechat') {
|
||||
$oauth = WechatService::create()->getApplication()->oauth;
|
||||
$oauth = WechatService::create(true)->getApplication()->oauth;
|
||||
$accessToken = $oauth->getAccessToken($data['code']);
|
||||
try {
|
||||
$wechatInfo = $oauth->user(new AccessToken(['access_token' => $data['code'], 'openid' => $data['openid']]))->getOriginal();
|
||||
$wechatInfo = $oauth->user($accessToken)->getOriginal();
|
||||
} catch (Exception $e) {
|
||||
throw new ValidateException('授权失败[001]' . $e->getMessage());
|
||||
}
|
||||
@ -909,10 +924,15 @@ class Auth extends BaseController
|
||||
public function authLogin()
|
||||
{
|
||||
$auth = $this->request->param('auth');
|
||||
$users = $this->authInfo($auth, systemConfig('is_phone_login') !== '1');
|
||||
$createUser = true;
|
||||
if ($auth['type'] == 'app_wechat' || systemConfig('is_phone_login') == '1') {
|
||||
$createUser = false;
|
||||
}
|
||||
$users = $this->authInfo($auth, $createUser);
|
||||
if (!$users)
|
||||
return app('json')->fail('授权失败');
|
||||
$authInfo = $users[0];
|
||||
/** @var UserRepository $userRepository */
|
||||
$userRepository = app()->make(UserRepository::class);
|
||||
$user = $users[1] ?? $userRepository->wechatUserIdBytUser($authInfo['wechat_user_id']);
|
||||
$code = (int)($auth['auth']['spread_code']['id'] ?? $auth['auth']['spread_code'] ?? '');
|
||||
@ -920,7 +940,7 @@ class Auth extends BaseController
|
||||
if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) {
|
||||
$auth['auth']['spread'] = $info['third_id'];
|
||||
}
|
||||
if (!$user) {
|
||||
if (!$user || empty($user['account']) || empty($user['phone'])) {
|
||||
$uni = uniqid(true, false) . random_int(1, 100000000);
|
||||
$key = 'U' . md5(time() . $uni);
|
||||
Cache::set('u_try' . $key, ['id' => $authInfo['wechat_user_id'], 'type' => $authInfo['user_type'], 'spread' => $auth['auth']['spread'] ?? 0], 3600);
|
||||
@ -930,6 +950,9 @@ class Auth extends BaseController
|
||||
if ($auth['auth']['spread'] ?? 0) {
|
||||
$userRepository->bindSpread($user, (int)($auth['auth']['spread']));
|
||||
}
|
||||
if (!empty($user['account'])) {
|
||||
$user = $userRepository->accountByUser($user['account']);
|
||||
}
|
||||
$tokenInfo = $userRepository->createToken($user);
|
||||
$userRepository->loginAfter($user);
|
||||
return app('json')->status(200, $userRepository->returnToken($user, $tokenInfo));
|
||||
@ -1651,4 +1674,110 @@ class Auth extends BaseController
|
||||
$data = $repository->getResult($type);
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并账号
|
||||
* @param UserRepository $repository
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function merge(UserRepository $repository)
|
||||
{
|
||||
$data = $this->request->params(['phone', 'sms_code', 'spread', 'pwd', 'auth_token', ['user_type', 'h5']]);
|
||||
$sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'login');
|
||||
if (!$sms_code && !env('APP_DEBUG')) {
|
||||
return app('json')->fail('验证码不正确');
|
||||
}
|
||||
$auth = Cache::get('u_try' . $data['auth_token']);
|
||||
$auth && Cache::delete('u_try' . $data['auth_token']);
|
||||
if (empty($auth)) {
|
||||
return app('json')->fail('授权已过期,请重新登录');
|
||||
}
|
||||
$user = $repository->wechatUserIdBytUser($auth['id']);
|
||||
if (!empty($user['account']) && !empty($user['phone'])) {
|
||||
return app('json')->fail('已绑定手机号');
|
||||
}
|
||||
$targetUser = $repository->accountByUser($data['phone']);
|
||||
if (empty($targetUser)) {
|
||||
if (!empty($user)) {
|
||||
$user->account = $data['phone'];
|
||||
$user->phone = $data['phone'];
|
||||
$user->save();
|
||||
$tokenInfo = $repository->createToken($user);
|
||||
return app('json')->success($repository->returnToken($user, $tokenInfo));
|
||||
} else {
|
||||
$targetUser = $repository->registr($data['phone'], $data['pwd'], $data['user_type']);
|
||||
$repository->bindSpread($targetUser, intval($data['spread']));
|
||||
}
|
||||
}
|
||||
$repository->syncBaseAuth($auth, $targetUser);
|
||||
if (!empty($user)) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
|
||||
StoreOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
|
||||
StoreOrderProduct::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
|
||||
UserBill::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
|
||||
FinancialRecord::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]);
|
||||
UserAddress::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
|
||||
StoreConsumptionUser::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
|
||||
StoreConsumptionDetail::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]);
|
||||
StoreRefundOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
|
||||
UserRecharge::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
|
||||
StoreOrderStatus::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
|
||||
if ($user->now_money > 0) {
|
||||
$user->now_money = 0;
|
||||
$targetUser->now_money = bcadd($targetUser->now_money, $user->now_money, 2);
|
||||
$targetUser->save();
|
||||
}
|
||||
$merchant = Merchant::where('uid', $targetUser['uid'])->find();
|
||||
if (!empty($merchant)) {
|
||||
$orders = StoreOrder::with(['refundOrder' => function(Query $query) {
|
||||
$query->where('status', '<>', -1)->field('order_id,refund_price');
|
||||
}])->where('uid', $user['uid'])
|
||||
->whereIn('status', [0, 1, 2, 3, 9, 10])
|
||||
->field('order_id,uid,total_price')
|
||||
->select()->toArray();
|
||||
$otherOrders = StoreOrderOther::with(['refundOrder' => function(Query $query) {
|
||||
$query->where('status', '<>', -1)->field('order_id,refund_price');
|
||||
}])->where('uid', $user['uid'])
|
||||
->whereIn('status', [0, 1, 2, 3, 9, 10])
|
||||
->field('order_id,uid,total_price')
|
||||
->select()->toArray();
|
||||
$purchaseAmount = 0;
|
||||
foreach ($orders as $order) {
|
||||
$purchaseAmount = bcadd($purchaseAmount, $order['total_price'], 2);
|
||||
foreach ($order['refundOrder']as $refundOrder) {
|
||||
$purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2);
|
||||
}
|
||||
}
|
||||
unset($refundOrder, $order);
|
||||
foreach ($otherOrders as $otherOrder) {
|
||||
$purchaseAmount = bcadd($purchaseAmount, $otherOrder['total_price'], 2);
|
||||
foreach ($otherOrder['refundOrder']as $refundOrder) {
|
||||
$purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2);
|
||||
}
|
||||
}
|
||||
unset($refundOrder, $otherOrder);
|
||||
if ($purchaseAmount > 0) {
|
||||
$merchant->purchase_amount = bcadd($merchant->purchase_amount, $purchaseAmount, 2);
|
||||
$merchant->save();
|
||||
}
|
||||
}
|
||||
if (!empty($user)) {
|
||||
$user->wechat_user_id = 0;
|
||||
$user->save();
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new ValidateException('绑定出错');
|
||||
}
|
||||
}
|
||||
$tokenInfo = $repository->createToken($targetUser);
|
||||
return app('json')->success($repository->returnToken($targetUser, $tokenInfo));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -405,14 +405,14 @@ class StoreOrder extends BaseController
|
||||
return app('json')->success($list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取商户押金列表
|
||||
*/
|
||||
public function getOrderAutoMarginList($merId){
|
||||
[$page, $limit] = $this->getPage();
|
||||
$select= Db::name('financial_record')->where('mer_id',$merId)->where('type',1)
|
||||
->where('financial_type','auto_margin')->where('financial_pm',0)
|
||||
$select= Db::name('financial_record')->where('mer_id',$merId)
|
||||
->where('financial_type','auto_margin')
|
||||
->page($page)->limit($limit)->order('financial_record_id','desc')->select();
|
||||
return app('json')->success($select);
|
||||
|
||||
|
@ -301,10 +301,10 @@ class Merchant extends BaseController
|
||||
if (empty($merchantInfo)) {
|
||||
return app('json')->fail('参数错误');
|
||||
}
|
||||
$margin = Db::name('MerchantType')->where('mer_type_id', $merchantInfo['type_id'])->value('margin');
|
||||
$merchantInfo['unpaid_margin'] = bcsub($margin, $merchantInfo['paid_margin'], 2);
|
||||
if ($merchantInfo['margin'] == 0) {
|
||||
$merchantInfo['margin'] = $merchantInfo['unpaid_margin'];
|
||||
$merchantInfo['unpaid_margin'] = bcsub($merchantInfo['margin'], $merchantInfo['paid_margin'], 2);
|
||||
if ($merchantInfo['margin'] <= 0) {
|
||||
$merchantInfo['unpaid_margin'] = 0;
|
||||
$merchantInfo['paid_margin'] = 0;
|
||||
}
|
||||
return app('json')->success($merchantInfo);
|
||||
}
|
||||
|
@ -10,10 +10,8 @@
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\controller\api\user;
|
||||
|
||||
|
||||
use app\common\dao\store\order\StoreOrderDao;
|
||||
use app\common\model\store\order\StoreOrderOther;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
@ -98,6 +96,7 @@ class User extends BaseController
|
||||
'now_money' => $user->now_money,
|
||||
'broken_day' => (int)systemConfig('lock_brokerage_timer'),
|
||||
'user_extract_min' => (int)systemConfig('user_extract_min'),
|
||||
'mer_extract_min' => (int)systemConfig('extract_minimum_num'),
|
||||
];
|
||||
return app('json')->success($data);
|
||||
}
|
||||
@ -564,26 +563,16 @@ class User extends BaseController
|
||||
public function merchantRecord()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$userIds = UserModel::where('spread_uid', $this->user->uid)->column('uid');
|
||||
$userIds = UserModel::where('spread_uid', $this->user->uid)->page($page, $limit)->column('uid');
|
||||
$query = Merchant::whereIn('uid', $userIds)->where('is_del', 0);
|
||||
$merchants = $query->page($page, $limit)
|
||||
->field('mer_id,mer_name,uid,real_name')
|
||||
->field('mer_id,mer_name,uid,real_name,sale_amount,purchase_amount as buy_amount')
|
||||
->select()->toArray();
|
||||
$dao = new StoreOrderDao();
|
||||
/** @var PresellOrderRepository $preSellDao */
|
||||
$preSellRepo = app()->make(PresellOrderRepository::class);
|
||||
$merchants = reset_index($merchants, 'uid');
|
||||
$result = [];
|
||||
foreach ($userIds as $userId) {
|
||||
if (isset($merchants[$userId])) {
|
||||
$merchant = $merchants[$userId];
|
||||
$saleOrderQuery = $dao->search(['mer_id' => $merchant['mer_id']])->whereIn('StoreOrder.status', [0, 1, 2, 3, 9, 10])->where('paid', 1);
|
||||
$saleOrderIds = $saleOrderQuery->column('order_id');
|
||||
$saleAmount1 = $saleOrderQuery->sum('StoreOrder.pay_price');
|
||||
$saleAmount2 = $preSellRepo->search(['paid' => 1, 'order_ids' => $saleOrderIds])->sum('pay_price');
|
||||
$merchant['sale_amount'] = bcadd($saleAmount1, $saleAmount2, 2);
|
||||
$merchant['buy_amount'] = StoreOrderOther::where('uid', $merchant['uid'])->whereIn('status', [0, 1, 2, 3, 9, 10])->where('paid', 1)->sum('pay_price');
|
||||
$merchant['buy_amount'] = bcadd($merchant['buy_amount'], 0, 2);
|
||||
$merchant['status'] = 1;
|
||||
$result[] = $merchant;
|
||||
} else {
|
||||
|
@ -20,23 +20,28 @@ class ActivateConsumptionListen extends TimerService implements ListenerInterfac
|
||||
{
|
||||
$this->tick(1000 * 60, function () {
|
||||
Log::info('定时任务:激活商户补贴');
|
||||
$count = 0;
|
||||
$couponId = StoreConsumption::where('type', StoreConsumption::TYPE_RECHARGE)->value('coupon_id');
|
||||
if (empty($couponId)) {
|
||||
return;
|
||||
}
|
||||
$buyCouponId = StoreConsumption::where('type', StoreConsumption::TYPE_PULL_CONSUMPTION)->value('coupon_id');
|
||||
$storeConsumptionUser = StoreConsumptionUser::where('coupon_id', $couponId)
|
||||
->where('status', StoreConsumptionUser::STATUS_REPEAL)
|
||||
->select();
|
||||
foreach ($storeConsumptionUser as $item) {
|
||||
$saleTotal = Merchant::where('uid', $item['uid'])->value('sale_amount');
|
||||
if ($saleTotal >= $item['order_amount'] && $item['balance'] <= 0) {
|
||||
$balance = StoreConsumptionUser::where('coupon_id', $buyCouponId)->where('uid', $item['uid'])->value('balance');
|
||||
if ($saleTotal >= $item['order_amount'] && $balance <= 0) {
|
||||
$item->status = StoreConsumptionUser::STATUS_UNUSED;
|
||||
$item->start_time = date('Y-m-d H:i:s');
|
||||
$item->end_time = date('Y-m-d H:i:s', strtotime('+1 year'));
|
||||
$item->save();
|
||||
UserBill::where('link_id', $item['coupon_user_id'])->where('type', 'red_pack_2')->update(['status', 1]);
|
||||
UserBill::where('link_id', $item['coupon_user_id'])->where('type', 'red_pack_2')->update(['status' => 1]);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
Log::info('定时任务:激活商户补贴,执行数量:' . $count);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -18,24 +18,39 @@ use app\common\repositories\user\UserBillRepository;
|
||||
use crmeb\interfaces\ListenerInterface;
|
||||
use crmeb\services\TimerService;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class AutoUnlockMerchantMoneyListen extends TimerService implements ListenerInterface
|
||||
{
|
||||
public function handle($event): void
|
||||
{
|
||||
$this->tick(1000 * 60 * 20, function () {
|
||||
request()->clearCache();
|
||||
$userBill = app()->make(UserBillRepository::class);
|
||||
$timer = ((int)systemConfig('mer_lock_time'));
|
||||
$time = date('Y-m-d H:i:s', $timer ? strtotime("- $timer day") : time());
|
||||
$bills = $userBill->getTimeoutMerchantMoneyBill($time);
|
||||
$merchant = app()->make(MerchantRepository::class);
|
||||
foreach ($bills as $bill) {
|
||||
Db::transaction(function () use ($bill, $merchant) {
|
||||
$merchant->addMoney($bill->mer_id, $bill->number);
|
||||
$bill->status = 1;
|
||||
$bill->save();
|
||||
});
|
||||
$this->tick(1000 * 60 * 60, function () {
|
||||
if (time() >= strtotime('today 18:00:00') && time() <= strtotime('today 20:00:00')) {
|
||||
request()->clearCache();
|
||||
/** @var UserBillRepository $userBill */
|
||||
$userBill = app()->make(UserBillRepository::class);
|
||||
// $timer = ((int)systemConfig('mer_lock_time'));
|
||||
// $time = date('Y-m-d H:i:s', $timer ? strtotime("- $timer day") : time());
|
||||
$time = date('Y-m-d 00:00:00');
|
||||
$bills = $userBill->getTimeoutMerchantMoneyBill($time);
|
||||
$merchant = app()->make(MerchantRepository::class);
|
||||
$count = 0;
|
||||
foreach ($bills as $bill) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
$merchant->addMoney($bill->mer_id, $bill->number);
|
||||
$bill->status = 1;
|
||||
$bill->save();
|
||||
Db::commit();
|
||||
$count++;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
Log::error('商户冻结金额解冻出错:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
if ($count > 0) {
|
||||
Log::info('商户冻结金额解冻成功:' . $count);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -676,8 +676,13 @@ class ExcelService
|
||||
$query = app()->make(FinancialRepository::class)->search($where)->with('merchant');
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
|
||||
foreach ($list as $item) {
|
||||
if ($item->financial_type == 1) {
|
||||
if (empty($item->financial_account->bank)) {
|
||||
$acount = '';
|
||||
continue;
|
||||
}
|
||||
$acount = '姓名:' . $item->financial_account->name . PHP_EOL;
|
||||
$acount .= '银行名称:' . $item->financial_account->bank . PHP_EOL;
|
||||
$acount .= '银行卡号:' . $item->financial_account->bank_code;
|
||||
@ -707,6 +712,59 @@ class ExcelService
|
||||
return compact('count', 'header', 'title', 'export', 'foot', 'filename');
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现银行账单导出
|
||||
* @param array $where
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return array
|
||||
*/
|
||||
public function withdrawalBill(array $where, int $page, int $limit)
|
||||
{
|
||||
$title = [
|
||||
'转账记录',
|
||||
'生成时间:' . date('Y-m-d H:i:s', time())
|
||||
];
|
||||
$header = ['编号', '收款方账号', '收款方户名', '是否农业银行', '开户银行(行别)', '开户行大额行号', '开户行支行名称', '金额','用途(附言)'];
|
||||
$filename = '转账记录_' . time();
|
||||
$export = [];
|
||||
$where['type'] = 0; //申请类型默认为余额
|
||||
|
||||
$query = app()->make(FinancialRepository::class)->search($where)->with('merchant');
|
||||
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
foreach ($list as $item) {
|
||||
$checkRes = "";
|
||||
if (!empty($item->financial_account) && isset($item->financial_account->bank)) {
|
||||
$bankName = $item->financial_account->bank;
|
||||
if (preg_match("/农业银行/i", $bankName)) {
|
||||
$checkRes = "是";
|
||||
} else {
|
||||
$checkRes = "否";
|
||||
}
|
||||
}else{
|
||||
//测试数据有未存在的数据
|
||||
$bankName='';
|
||||
}
|
||||
|
||||
$export[] = [
|
||||
$item->financial_sn,
|
||||
$item->financial_account->bank_code??'',
|
||||
$item->financial_account->name??'',//收款方户名1
|
||||
$checkRes,
|
||||
$bankName,//'开户银行(行别)
|
||||
'',//'开户行大额行号'
|
||||
$item->financial_account->bank_branch??'',
|
||||
$item->extract_money,
|
||||
$item->mark
|
||||
];
|
||||
}
|
||||
$foot = '';
|
||||
return compact('count', 'header', 'title', 'export', 'foot', 'filename');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 用户提现申请
|
||||
* @param array $where
|
||||
|
@ -279,6 +279,11 @@ Route::group(function () {
|
||||
Route::get('export', 'Financial/export')->name('systemFinancialExport')->option([
|
||||
'_alias' => '导出',
|
||||
]);
|
||||
|
||||
Route::get('bill', 'Financial/billExport')->name('systemFinancialBillExport')->option([
|
||||
'_alias' => '账单导出',
|
||||
]);
|
||||
|
||||
})->prefix('admin.system.financial.')->option([
|
||||
'_path' => '/accounts/transferRecord',
|
||||
'_auth' => true,
|
||||
|
@ -739,6 +739,8 @@ Route::group('api/', function () {
|
||||
Route::post('auth/apple', 'api.Auth/appleAuth');
|
||||
//修改密码
|
||||
Route::post('user/change_pwd', 'api.Auth/changePassword');
|
||||
//合并账号
|
||||
Route::post('user/merge', 'api.auth/merge');
|
||||
//验证码
|
||||
Route::post('auth/verify', 'api.Auth/verify');
|
||||
Route::post('auth/verifyCode', 'api.Auth/verifyCode');
|
||||
|
Loading…
x
Reference in New Issue
Block a user