Merge pull request 'dev' (#26) from dev into main

Reviewed-on: #26
This commit is contained in:
mkm 2024-06-28 19:12:32 +08:00
commit 7036f065b3
25 changed files with 700 additions and 491 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace app\admin\controller\user_product_storage;
use app\admin\controller\BaseAdminController;
use app\admin\lists\user_product_storage\UserProductStorageLists;
/**
* 用户商品储存控制器
* Class UserProductStorageController
* @package app\admin\controller\user_product_storage
*/
class UserProductStorageController extends BaseAdminController
{
/**
* @notes 获取用户商品储存列表
* @return \think\response\Json
* @author admin
* @date 2024/06/28 11:05
*/
public function lists()
{
return $this->dataLists(new UserProductStorageLists());
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace app\admin\controller\user_product_storage_log;
use app\admin\controller\BaseAdminController;
use app\admin\lists\user_product_storage_log\UserProductStorageLogLists;
use app\admin\logic\user_product_storage_log\UserProductStorageLogLogic;
use app\admin\validate\user_product_storage_log\UserProductStorageLogValidate;
/**
* 用户商品储存操作日志控制器
* Class UserProductStorageLogController
* @package app\admin\controller\user_product_storage_log
*/
class UserProductStorageLogController extends BaseAdminController
{
/**
* @notes 获取用户商品储存操作日志列表
* @return \think\response\Json
* @author admin
* @date 2024/06/28 11:15
*/
public function lists()
{
return $this->dataLists(new UserProductStorageLogLists());
}
}

View File

@ -6,6 +6,7 @@ use app\admin\lists\BaseAdminDataLists;
use app\common\enum\OrderEnum;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_order\StoreOrder;
use app\common\model\user\User;
class StoreRefundOrderLists extends BaseAdminDataLists implements ListsSearchInterface
{
@ -38,7 +39,7 @@ class StoreRefundOrderLists extends BaseAdminDataLists implements ListsSearchInt
public function lists(): array
{
$this->searchWhere[] = ['refund_status','>', 0];
return StoreOrder::with(['user', 'staff', 'product' => function ($query) {
return StoreOrder::with(['staff', 'product' => function ($query) {
$query->field(['id', 'oid', 'product_id', 'cart_info']);
}])
->where($this->searchWhere)
@ -46,6 +47,15 @@ class StoreRefundOrderLists extends BaseAdminDataLists implements ListsSearchInt
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
if ($item['uid'] <= 0) {
$item['nickname'] = '游客';
} else {
$id = $item['uid'];
$user=User::where('id', $item['uid'])->field('real_name,nickname')->find();
if($user){
$item['nickname'] =$user['real_name']!=''?$user['real_name'].'|'.$id:$user['nickname'].'|'.$id;
}
}
$item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : '';
$item['refund_status_name'] = OrderEnum::refundStatus($item['refund_status']) ?? '';
$item['refund_type_name'] = OrderEnum::refundType($item['refund_type']) ?? '';

View File

@ -11,6 +11,7 @@ use app\common\lists\ListsExcelInterface;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
use app\common\model\vip_flow\VipFlow;
use support\Db;
class UserLists extends BaseAdminDataLists implements ListsExcelInterface
{
@ -41,7 +42,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
$params = $this->params;
$where = [];
if(isset($params['nickname']) && $params['nickname'] != ''){
$where[] = ['nickname','like','%'.$params['nickname'].'%'];
$where[] = ['real_name|nickname','like','%'.$params['nickname'].'%'];
}
if(isset($params['account']) && $params['account'] != ''){
$where[] = ['account','like','%'.$params['account'].'%'];
@ -76,6 +77,30 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
$item['return_money'] = VipFlow::
where(['user_id'=>$item['id'],'status'=>0])
->sum('number')??0;
$address = UserAddress::where('uid',$item['id'])->find();
$item['city'] = '';
$item['area'] = '';
$item['street'] = '';
$item['village'] = '';
$item['brigade'] = '';
if($address){
if($address['city']){
$item['city'] = \think\facade\Db::name('geo_city')->where('city_code',$address['city'])->value('city_name')??'';
}
if($address['area']){
$item['area'] = \think\facade\Db::name('geo_area')->where('area_code',$address['area'])->value('area_name')??'';
}
if($address['street']){
$item['street'] = \think\facade\Db::name('geo_street')->where('street_code',$address['street'])->value('street_name')??'';
}
if($address['village']){
$item['village'] = \think\facade\Db::name('geo_village')->where('village_code',$address['village'])->value('village_name')??'';
}
if($address['brigade']){
$item['brigade'] = $address['brigade'] ? $address['brigade'].'队':'';
}
}
$item['format_address'] = $item['city'].'/'.$item['area'].'/'.$item['street'].'/'.$item['village'].'/'. $item['brigade'];
}
return $lists;

View File

@ -0,0 +1,85 @@
<?php
namespace app\admin\lists\user_product_storage;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\user_product_storage\UserProductStorage;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
/**
* 用户商品储存列表
* Class UserProductStorageLists
* @package app\admin\listsuser_product_storage
*/
class UserProductStorageLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/06/28 11:05
*/
public function setSearch(): array
{
return [
'=' => ['uid', 'oid', 'product_id'],
'between_time' => ['create_time'],
];
}
/**
* @notes 获取用户商品储存列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/06/28 11:05
*/
public function lists(): array
{
$status=$this->request->get('status',1);
if($status==1){
$this->searchWhere[]=['status','=',1];//只显示正常状态的记录,不显示已出库完的记录
}
return UserProductStorage::where($this->searchWhere)
->field(['id', 'uid', 'oid', 'product_id', 'nums', 'status','create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$user=User::where('id',$item['uid'])->field('nickname,real_name')->find();
$item['nickname']=$user['real_name']?$user['real_name'].'|'.$item['uid']:$user['nickname'].'|'.$item['uid'];
$find=StoreProduct::where('id',$item['product_id'])->field('store_name,image,price')->find();
$item['store_name']=$find['store_name'];
$item['image']=$find['image'];
$item['price']=$find['price'];
if($item['status']==1){
$item['status_name']='正常';
}else{
$item['status_name']='已出库完';
}
return $item;
})
->toArray();
}
/**
* @notes 获取用户商品储存数量
* @return int
* @author admin
* @date 2024/06/28 11:05
*/
public function count(): int
{
return UserProductStorage::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace app\admin\lists\user_product_storage_log;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\user_product_storage_log\UserProductStorageLog;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
/**
* 用户商品储存操作日志列表
* Class UserProductStorageLogLists
* @package app\admin\listsuser_product_storage_log
*/
class UserProductStorageLogLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/06/28 11:15
*/
public function setSearch(): array
{
return [
'between_time' => ['create_time'],
];
}
/**
* @notes 获取用户商品储存操作日志列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/06/28 11:15
*/
public function lists(): array
{
return UserProductStorageLog::where($this->searchWhere)
->field(['id', 'oid', 'uid', 'product_id', 'store_id', 'financial_pm', 'nums'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$user=User::where('id',$item['uid'])->field('nickname,real_name')->find();
$item['system_store_name']=SystemStore::where('id',$item['store_id'])->value('name');
$item['nickname']=$user['real_name']?$user['real_name'].'|'.$item['uid']:$user['nickname'].'|'.$item['uid'];
$item['store_name']=StoreProduct::where('id',$item['product_id'])->value('store_name');
if($item['financial_pm']==1){
$item['financial_pm']='增加';
}else{
$item['financial_pm']='减少';
}
return $item;
})
->toArray();
}
/**
* @notes 获取用户商品储存操作日志数量
* @return int
* @author admin
* @date 2024/06/28 11:15
*/
public function count(): int
{
return UserProductStorageLog::where($this->searchWhere)->count();
}
}

View File

@ -48,7 +48,11 @@ class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterfa
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
$item['nickname']=User::where('id',$item['uid'])->value('nickname');
$id = $item['uid'];
$user=User::where('id', $item['uid'])->field('real_name,nickname')->find();
if($user){
$item['nickname'] =$user['real_name']!=''?$user['real_name'].'|'.$id:$user['nickname'].'|'.$id;
}
if($item['pay_time']>0){
$item['pay_time']=date('Y-m-d H:i:s',$item['pay_time']);
}else{

View File

@ -90,7 +90,7 @@ class UserLogic extends BaseLogic
'password' => $password,
'mobile' => $params['mobile'],
'label_id' => $params['label_id']??0,
'store_id' => $params['store_id']??0,
];
$res=User::create($data);
UserCreateLog::create([

View File

@ -28,7 +28,7 @@ use Webman\RedisQueue\Redis;
class IndexController extends BaseApiController
{
public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street', 'village', 'brigade', 'config'];
public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street', 'village', 'brigade', 'config','push'];
public function index()
{
@ -176,4 +176,13 @@ return json($a);
];
return $this->success('ok', $list);
}
public function push()
{
$name=$this->request->get('name');//用户名
$uid=$this->request->get('uid');//用户id
$type=$this->request->get('type','INDUSTRYMEMBERS');//类型
$a= PushService::push($name, $uid, ['type'=>$type,'msg'=>'支付超时,订单已被取消,请重新提交订单','data'=>['id'=>5]]);
return $this->success('ok',['data'=> $a]);
}
}

View File

@ -47,7 +47,7 @@ class PayController extends BaseApiController
} else {
if ($result && $result->event_type == 'REFUND.SUCCESS') {
$ciphertext = $result->resource['ciphertext'];
Cache::set('6logC'.time(),json_encode($ciphertext));
Cache::set('7logC'.time(),json_encode($ciphertext));
if ($ciphertext['refund_status'] === 'SUCCESS') {
//处理订单 -1判断是退的一单还是拆分的订单
$out_trade_no = $ciphertext['out_trade_no'] . '-1';

View File

@ -67,16 +67,16 @@ class StoreController extends BaseApiController
$recharge_type = $this->request->post('recharge_type',''); //微信支付条码
$code = $this->request->post('code','');//验证码
$phone = $params['mobile'];
if($code && $phone){
$remark = $phone.'_reporting';
$codeCache = Cache::get($remark);
if(empty($codeCache)){
return $this->fail('验证码不存在');
}
if ($codeCache != $code) {
return $this->fail('验证码错误');
}
}
// if($code && $phone){
// $remark = $phone.'_reporting';
// $codeCache = Cache::get($remark);
// if(empty($codeCache)){
// return $this->fail('验证码不存在');
// }
// if ($codeCache != $code) {
// return $this->fail('验证码错误');
// }
// }
if($params['price']>10000){
return $this->fail('充值金额不能大于10000');
}

View File

@ -9,10 +9,11 @@ use app\api\validate\UserValidate;
use app\common\enum\PayEnum;
use app\common\logic\PaymentLogic;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
use app\common\model\user_sign\UserSign;
use support\Cache;
use think\Exception;
use think\facade\Db;
/**
* 用户控制器
@ -244,6 +245,30 @@ class UserController extends BaseApiController
}
/**
* 用户信息
*/
public function other_user_info(){
$mobile=$this->request->get('mobile');
if($mobile){
$user=User::where('mobile',$mobile)->field('id,avatar,real_name,nickname,mobile,user_ship,purchase_funds,label_id')->find();
if($user){
$address=UserAddress::where('uid',$user['id'])->where('is_default',1)->find();
if($address){
$city_name=Db::name('geo_city')->where('city_code',$address['city'])->value('city_name');
$area_name=Db::name('geo_area')->where('area_code',$address['area'])->value('area_name');
$street_name=Db::name('geo_street')->where('street_code',$address['street'])->value('street_name');
$village_name=Db::name('geo_village')->where('village_code',$address['village'])->value('village_name');
$brigade_name=Db::name('geo_brigade')->where('id',$address['brigade'])->value('brigade_name');
$address['address_like']=$city_name.$area_name.$street_name.$village_name.$brigade_name;
}
$user['address_info']=$address;
return $this->success('ok',$user->toArray());
}else{
return $this->fail('用户不存在');
}
}
return $this->success('ok',[]);
}
}

View File

@ -48,20 +48,17 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
$pid = $this->request->get('pid',0);
$this->searchWhere[] = ['stock', '>', 0];
$this->searchWhere[] = ['status', '=', 1];
if($pid == 0 && $level ==1){
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('top_cate_id');
}
if($pid && $level ==2){
$this->searchWhere[] = ['top_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('two_cate_id');
}
if($pid && $level ==3){
}elseif($pid && $level ==3){
$this->searchWhere[] = ['two_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('cate_id');
}else{
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('top_cate_id');
}
$lists = [];
if ($cate_arr) {

View File

@ -99,14 +99,15 @@ class OrderLogic extends BaseLogic
$cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $price, 2); //订单支付金额
$cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2)??0; //门店零售价
// $cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2)??0; //vip售价
$cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2)??0; //vip售价
$cart_select[$k]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id'];
$cart_select[$k]['cart_num'] = $v['cart_num'];
$cart_select[$k]['verify_code'] = $params['verify_code'] ?? '';
//vip1待返回金额
// $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['vip_price'],2);
$cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['vip_price'],2);
// d($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],$cart_select[$k]['vip_price'] );
$cartInfo = $cart_select[$k];
$cartInfo['name'] = $find['store_name'];
@ -431,17 +432,14 @@ class OrderLogic extends BaseLogic
'staff_id' => $params['staff_id']??0,
'update_time' => time(),
], ['oid' => $order['id']]);
// $financeFlow = (new StoreFinanceFlowLogic)->getStoreOrder($data['id'], $data['store_id']);
// if (!empty($financeFlow)) {
// $capitalFlowLogic = new CapitalFlowLogic($data->store, 'store');
// $capitalFlowLogic->storeIncome('store_order_income', 'order', $data['id'], $financeFlow['number']);
// }
PayNotifyLogic::descStock($order['id']);
$financeFlow=new StoreFinanceFlow();
$financeFlowLogic=new StoreFinanceFlowLogic();
$select_1=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>['in'=>14,15],'other_uid'=>['>'=>0]])->select();
$select_1=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>['in'=>14,15,16]])->select();
foreach($select_1 as $k=>$v){
$financeFlowLogic->updateStatusUser($v['id'],$v['other_uid'],$v['number'],$v['order_id']);
if($v['other_uid']>0){
$financeFlowLogic->updateStatusUser($v['id'],$v['other_uid'],$v['number'],$v['order_id']);
}
}
if($order['uid'] && $order['pay_price'] >= 500){
$user_number = bcmul($order['pay_price'], '0.10', 2);
@ -454,67 +452,9 @@ class OrderLogic extends BaseLogic
$financeFlowLogic->updateStatusUser($spread_find['id'],$order['spread_uid'],$spread_find['number'],$order['order_id']);
}
}
$deposit=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>11])->value('number');
$money=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>2])->value('number');
$deposit=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>11])->value('number')??0;
$money=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>2])->value('number')??0;
$financeFlowLogic->updateStatusStore($order['id'],$order['store_id'],$money,$deposit);
/* $check = Db::name('user_sign_log')->where('order_id',$order['order_id'])
->where(['status'=>0])
->find();//$check['number']扣的
if($check){
// User::where('id',$order['uid'])->inc('purchase_funds',$check['number'])->update();
// $user_number = bcmul($order['pay_price'], '0.10', 2);
$base = UserSign::where([
'uid'=>$order['uid'],
'type'=>1,
'status'=>1
])->find();
$user_sing = new UserSign();
if($base['number'] > 0 && $base['number'] >= $check['number']){
$sing = [
'uid' => $order['uid'],
'order_id' => $order['order_id'].'-b',
'title' => '返还兑换券',
'financial_pm' => 1,
'store_id' => $order['store_id'],
'status' => 1,
];
$sing['number'] = $check['number'];
$user_sing->save($sing);
User::where('id',$order['uid'])->inc('integral',$check['number'])->update();
//减少
UserSign::where('id',$check['sid'])->dec('number',$check['number'])->update();
if($base['number'] == $check['number']){
UserSign::where([
'id'=>$order['sid']
])->update(['status'=>1]);
}
}
if($base['number'] < $check['number']){
$sing = [
'uid' => $order['uid'],
'order_id' => $order['order_id'].'-b',
'title' => '返还兑换券',
'financial_pm' => 1,
'store_id' => $order['store_id'],
'status' => 1,
];
$sing['number'] = $base['number'];
$user_sing->save($sing);
UserSign::where('id',$check['sid'])->dec('number',$base['number'])->update();
User::where('id',$order['uid'])->inc('integral',$base['number'])->update();
UserSign::where([
'id'=>$order['sid']
])->update(['status'=>1]);
}
Db::name('user_sign_log')->where('order_id',$order['order_id'])->update(['status'=>1]);
}*/
Db::commit();
return true;
} catch (\Exception $e) {

View File

@ -20,6 +20,7 @@ use app\common\{logic\BaseLogic,
model\vip_flow\VipFlow,
service\SmsService,
service\wechat\WeChatMnpService};
use app\common\model\user_label\UserLabel;
use support\Cache;
use think\facade\Db;
@ -83,7 +84,7 @@ class UserLogic extends BaseLogic
{
$data = User::with(['userShip'])->where('id',$uid)
->field('id,avatar,real_name,nickname,account,mobile,sex,login_ip,now_money,total_recharge_amount,user_ship
,purchase_funds,integral,pay_password')
,purchase_funds,integral,pay_password,label_id')
->find();
//判断是不是员工
if($data){
@ -105,9 +106,11 @@ class UserLogic extends BaseLogic
$data['store_id'] = $check['store_id'];
}
}
$data['label_name']=UserLabel::where('label_id',$data['label_id'])->value('label_name');
$data['return_money'] = Db::name('vip_flow')->
where(['user_id'=>$uid,'status'=>0])
->sum('number');
$data['return_money'] = bcadd($data['return_money'],0,2);
//小程序 未核销的订单
$data['no_writeoff'] = StoreOrder::where([
'is_writeoff'=>0,'uid'=>$uid
@ -303,10 +306,10 @@ class UserLogic extends BaseLogic
//礼品券明细
$query = UserSign::where(['uid'=>$uid]);
if($params['mark'] == 1){
$query->where('financial_pm',0);
$query->where('financial_pm',1);
}
if($params['mark'] == 2){
$query->where('financial_pm',1);
$query->where('financial_pm',0);
}
$count = $query->count();
$data =$query

View File

@ -39,8 +39,8 @@ class CapitalFlowLogic extends BaseLogic
$model->link_id = $linkId;
$model->amount = $amount;
if($type){
$model->before_balance = $this->user['now_money'];
$model->balance = $this->user['now_money'];
$model->before_balance = $this->user['purchase_funds'];
$model->balance = bcadd($this->user['purchase_funds'], $amount, 2);
}else{
$model->before_balance = $this->user['now_money'];
$model->balance = bcadd($this->user['now_money'], $amount, 2);
@ -73,8 +73,8 @@ class CapitalFlowLogic extends BaseLogic
$model->link_id = $linkId;
$model->amount = $amount;
if($payType == OrderEnum::BALANCE_PAYMEN_NO){
$model->before_balance = $this->user['now_money'];
$model->balance = $this->user['now_money'];
$model->before_balance = $this->user['purchase_funds'];
$model->balance = bcsub($this->user['purchase_funds'], $amount, 2);
}else{
$model->before_balance = $this->user['now_money'];
$model->balance = bcsub($this->user['now_money'], $amount, 2);

View File

@ -12,105 +12,62 @@ class CommissionLogic extends BaseLogic
/**
* 走村长分润
*/
public static function setVillage($order, $transaction_id)
public static function setVillage($order,$village_uid=0,$brigade_uid=0, $transaction_id=0)
{
$village_uid=0;
$brigade_uid=0;
if ($order['uid'] > 0) {
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
if ($address) {
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($arr1) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id');
if ($uid) {
$village_uid = $uid;
}
}
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
if ($arr2) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id');
if ($uid) {
$brigade_uid = $uid;
}
}
}
}
self::user($order, 0.05, $transaction_id,$village_uid,14);//村长
self::user($order, 0.03, $transaction_id,0,12);//会员、厨师
self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
self::user($order, 0.01, $transaction_id,0,16);//其他
$user_1=self::user($order, 0.05, $transaction_id,$village_uid,14);//村长
$user_2=self::user($order, 0.03, $transaction_id,0,12);//会员、厨师
$user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
$platform=self::platform($order, 0.02, $transaction_id);//平台
$store=self::store($order, 0.05, $transaction_id,0);//门店
$user_4=self::user($order, 0.02, $transaction_id,0,16);//其他
$moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2);
self::suppliter($order, $moeny, $transaction_id);
}
/**
* 走队长分润
*/
public static function setBrigade($order, $transaction_id)
public static function setBrigade($order,$village_uid=0,$brigade_uid=0, $transaction_id=0)
{
$village_uid=0;
$brigade_uid=0;
if ($order['uid'] > 0) {
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
if ($address) {
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($arr1) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id');
if ($uid) {
$village_uid = $uid;
}
}
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
if ($arr2) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id');
if ($uid) {
$brigade_uid = $uid;
}
}
}
}
self::user($order, 0.05, $transaction_id,$brigade_uid,14);//队长
self::user($order, 0.03, $transaction_id,0,12);////会员、厨师
self::user($order, 0.01, $transaction_id,$village_uid,15);//村长
self::user($order, 0.01, $transaction_id,0,16);//其他
$user_1=self::user($order, 0.05, $transaction_id,$brigade_uid,14);//队长
$user_2=self::user($order, 0.03, $transaction_id,0,12);////会员、厨师
$user_3=self::user($order, 0.01, $transaction_id,$village_uid,15);//村长
$platform=self::platform($order, 0.02, $transaction_id);//平台
$store=self::store($order, 0.05, $transaction_id,0);//门店
$user_4=self::user($order, 0.02, $transaction_id,0,16);//其他
$moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2);
self::suppliter($order, $moeny, $transaction_id);
}
/**
* 走厨师分润
*/
public static function setCook($order, $transaction_id)
public static function setCook($order,$village_uid=0,$brigade_uid=0, $transaction_id=0)
{
$village_uid=0;
$brigade_uid=0;
if ($order['uid'] > 0) {
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
if ($address) {
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($arr1) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id');
if ($uid) {
$village_uid = $uid;
}
}
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
if ($arr2) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id');
if ($uid) {
$brigade_uid = $uid;
}
}
}
}
self::user($order, 0.07, $transaction_id,0,12);//会员、厨师
self::user($order, 0.01, $transaction_id,$village_uid,14);//村长
self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
self::user($order, 0.01, $transaction_id,0,16);//其他
$user_1=self::user($order, 0.07, $transaction_id,0,12);//会员、厨师
$user_2=self::user($order, 0.01, $transaction_id,$village_uid,14);//村长
$user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
$platform=self::platform($order, 0.02, $transaction_id);//平台
$store=self::store($order, 0.05, $transaction_id,0);//门店
$user_4=self::user($order, 0.02, $transaction_id,0,16);//其他
$moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2);
self::suppliter($order, $moeny, $transaction_id);
}
/**
* 走线下分润
*/
public static function setStore($order, $transaction_id)
public static function setStore($order, $transaction_id=0)
{
self::platform($order, 0.05, $transaction_id);//平台
self::store($order, 0.02, $transaction_id,0);//门店
self::user($order, 0.01, $transaction_id,0,16);//其他
$platform= self::platform($order, 0.05, $transaction_id);//平台
$store= self::store($order, 0.02, $transaction_id,0);//门店
$user= self::user($order, 0.01, $transaction_id,0,16);//其他
$moeny=bcadd(bcadd($platform,$store,2),$user,2);
self::suppliter($order, $moeny, $transaction_id);
}
@ -122,10 +79,28 @@ class CommissionLogic extends BaseLogic
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order=$order;
$financeLogic->user['uid']=$order['uid'];
$fees = bcdiv(bcmul($order['pay_price'], $platformRate, 2), 1, 2);
if ($fees > 0) {
$financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费
$financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出
$financeLogic->save();
}
return $fees;
}
/**
* 供应链订单获得
*/
public static function suppliter($order, $platformRate, $transaction_id)
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order=$order;
$financeLogic->user['uid']=$order['uid'];
$fees = bcsub($order['pay_price'], $platformRate,2);
if ($fees > 0) {
$financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
$financeLogic->save();
}
}
/**
@ -142,7 +117,7 @@ class CommissionLogic extends BaseLogic
//缴纳齐全了就加商户没有就加到平台
$money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find();
$deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度
$store_profit = bcdiv(bcmul($order['pay_price'], $platformRate, 2), 1, 2);
$store_profit = bcmul($order['pay_price'], $platformRate, 2);
if ($deposit > 0) {
if ($deposit > $store_profit) {
if ($store_profit > 0) {
@ -167,6 +142,8 @@ class CommissionLogic extends BaseLogic
$financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费
}
}
$financeLogic->save();
return $store_profit;
}
/**
@ -188,8 +165,8 @@ class CommissionLogic extends BaseLogic
$financeLogic->order=$order;
$financeLogic->in($transaction_id, $fees, $enum, $order['store_id'], 0, 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
$financeLogic->save();
}
return $fees;
}
}

View File

@ -36,7 +36,7 @@ use Webman\RedisQueue\Redis;
* Class PayNotifyLogic
* @package app\api\logic
*/
class PayNotifyLogic extends BaseLogic
class PayNotifyLogicaaa extends BaseLogic
{
public static function handle($action, $orderSn, $extra = [], $type = 'wechat')

View File

@ -66,18 +66,19 @@ class PayNotifyLogic extends BaseLogic
public static function balancePay($orderSn, $extra = [])
{
$order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
$user = User::where('id', $order['uid'])->find();
if ($user['now_money'] < $order['pay_price']) {
throw new \Exception('余额不足');
}
$order->money = $order['pay_price'];
// $order->money = $order['pay_price'];
$order->paid = 1;
$order->pay_time = time();
if (!$order->save()) {
throw new \Exception('订单保存出错');
}
if($order['is_storage']==1){
$order->status=2;
if ($order['is_storage'] == 1) {
$order->status = 2;
UserProductStorageLogic::add($order);
}
// 减去余额
@ -94,9 +95,9 @@ class PayNotifyLogic extends BaseLogic
$capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']);
self::dealProductLog($order);
// if ($order['shipping_type'] == 3) {
// self::descStock($order['id']);
// }
// if ($order['shipping_type'] == 3) {
// self::descStock($order['id']);
// }
self::afterPay($order);
if ($extra && $extra['store_id']) {
$params = [
@ -106,6 +107,7 @@ class PayNotifyLogic extends BaseLogic
];
OrderLogic::writeOff($params);
}
return true;
// Redis::send('push-platform-print', ['id' => $order['id']], 60);
// PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
}
@ -182,8 +184,8 @@ class PayNotifyLogic extends BaseLogic
if (!$order->save()) {
throw new \Exception('订单保存出错');
}
if($order['is_storage']==1){
$order->status=2;
if ($order['is_storage'] == 1) {
$order->status = 2;
UserProductStorageLogic::add($order);
}
// 减去采购款
@ -206,15 +208,15 @@ class PayNotifyLogic extends BaseLogic
OrderLogic::writeOff($params);
}
self::dealProductLog($order);
// $count = UserSign::where([
// 'uid'=>$order['uid'],
// 'type'=>1,
// 'status'=>0
// ])->count();
//
// if($count){
// self::addFlowLog($order);
// }
// $count = UserSign::where([
// 'uid'=>$order['uid'],
// 'type'=>1,
// 'status'=>0
// ])->count();
//
// if($count){
// self::addFlowLog($order);
// }
// if($order['shipping_type'] == 3){
// self::descStock($order['id']);
// }
@ -223,85 +225,83 @@ class PayNotifyLogic extends BaseLogic
// Redis::send('push-platform-print', ['id' => $order['id']], 60);
// PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
}
//采购款支付后如果有对应的冻结的话就去反对应的log
public static function addFlowLog($order)
{
//查询当前用户有无对应的充值的冻结金额
if($order['uid'] >0){
if ($order['uid'] > 0) {
$query = UserSign::where([
'uid'=>$order['uid'],
'type'=>1,
'status'=>0
'uid' => $order['uid'],
'type' => 1,
'status' => 0
]);
// $query1 = clone $query;
// $ids = $query->column('id');
// $query1 = clone $query;
// $ids = $query->column('id');
$check = $query->sum('number');
// $count = $query1->count();
if($check && $check >0){
$backPurchase = bcmul($order['pay_price'],0.1,2);
// $count = $query1->count();
if ($check && $check > 0) {
$backPurchase = bcmul($order['pay_price'], 0.1, 2);
// if($count == 1){
//存在拆单子否
//少了就冻结减去这个对应的金额
$one = UserSign::where([
'uid'=>$order['uid'],
'type'=>1,
'status'=>0
])->find();
$data = [
'sid'=>$one['id'],
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '充值获得冻结兑换券',
'financial_pm' => 1,
'type' => 1,
'status' => 1,
];
// if($count == 1){
//存在拆单子否
//少了就冻结减去这个对应的金额
$one = UserSign::where([
'uid' => $order['uid'],
'type' => 1,
'status' => 0
])->find();
$data = [
'sid' => $one['id'],
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '充值获得冻结兑换券',
'financial_pm' => 1,
'type' => 1,
'status' => 1,
];
if($one['number'] >= $backPurchase){
// $wait = bcsub($one['number'],$backPurchase,2)??0;
$data['number'] =$backPurchase;
if ($one['number'] >= $backPurchase) {
// $wait = bcsub($one['number'],$backPurchase,2)??0;
$data['number'] = $backPurchase;
Db::name('user_sign_log')->insert($data);
Db::name('user_sign_log')->insert($data);
//总的减去采购款百分之十剩余的
// if(empty($wait)){
// UserSign::where('id',$one['id'])->update(
// [
// 'number'=>0,
// 'status'=>1
// ]
// );
// }else{
// //add
// UserSign::where('id',$one['id'])->update(
// [
// 'number'=>$wait
// ]
// );
// }
//并且加到对应的用户的采购款中
// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update();
}
else{
//对比采购款支付的多少 多了就拿冻结金额即可
$data['number'] =$one['number'];
//都存到对应的log日志
Db::name('user_sign_log')->insert($data);
// UserSign::where('id',$one['id'])->update(
// [
// 'number'=>0,
// 'status'=>1
// ]
// );
//并且加到对应的用户的采购款中
// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update();
}
//总的减去采购款百分之十剩余的
// if(empty($wait)){
// UserSign::where('id',$one['id'])->update(
// [
// 'number'=>0,
// 'status'=>1
// ]
// );
// }else{
// //add
// UserSign::where('id',$one['id'])->update(
// [
// 'number'=>$wait
// ]
// );
// }
//并且加到对应的用户的采购款中
// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update();
} else {
//对比采购款支付的多少 多了就拿冻结金额即可
$data['number'] = $one['number'];
//都存到对应的log日志
Db::name('user_sign_log')->insert($data);
// UserSign::where('id',$one['id'])->update(
// [
// 'number'=>0,
// 'status'=>1
// ]
// );
//并且加到对应的用户的采购款中
// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update();
}
/* else{
}
/* else{
//大于0的时候
//先处理金额大的再处理剩余的
//把所有的金额改为正的再加一条后再加
@ -356,9 +356,8 @@ class PayNotifyLogic extends BaseLogic
}*/
// }
// }
return true;
}
return true;
@ -380,8 +379,8 @@ class PayNotifyLogic extends BaseLogic
$order->status = 1;
$order->paid = 1;
$order->pay_time = time();
if($order['is_storage']==1){
$order->status=2;
if ($order['is_storage'] == 1) {
$order->status = 2;
UserProductStorageLogic::add($order);
}
if ($order->pay_type != 10) {
@ -426,7 +425,18 @@ class PayNotifyLogic extends BaseLogic
$orderRe->refund_time = time();
$orderRe->remarks = '';
$orderRe->save();
$purchase_funds = User::where('id',$orderRe['uid'])->value('purchase_funds');
$user = User::where('id',$orderRe['uid'])->find();
$capitalFlowDao = new CapitalFlowLogic($user);
if($purchase_funds >= $orderRe['price']){
User::where('id',$orderRe['uid'])->dec('purchase_funds',$orderRe['refund_price'])->update();
$capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $orderRe['id'], $orderRe['refund_price'], '', 1, $orderRe['store_id']);
}else{
User::where('id',$orderRe['uid'])->dec('purchase_funds',$purchase_funds)->update();
$capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $orderRe['id'], $purchase_funds, '', 1, $orderRe['store_id']);
}
self::descUserSing($orderRe);
// d($purchase_funds,$orderRe['refund_price'],$orderRe);
return true;
}
$order->status = OrderEnum::REFUND_PAY;
@ -440,7 +450,7 @@ class PayNotifyLogic extends BaseLogic
$user = User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user);
$deal_money = bcdiv($extra['amount']['refund'], 100, 2);
$check_user_sing = UserSign::where('order_id',$order['order_id'])->count();
$check_user_sing = UserSign::where('order_id', $order['order_id'])->count();
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额
$user->now_money = bcadd($user->now_money, $deal_money, 2);
@ -458,13 +468,13 @@ class PayNotifyLogic extends BaseLogic
//退款
$capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money);
}
if($check_user_sing){
if ($check_user_sing) {
self::descUserSing($order);
}
return true;
}
//积分
if($check_user_sing){
if ($check_user_sing) {
self::descUserSing($order);
}
//微信日志 user_order_refund
@ -475,12 +485,13 @@ class PayNotifyLogic extends BaseLogic
return true;
// self::afterPay($order,$extra['transaction_id']);
}
//退积分
//退积分-->订单
public static function descUserSing($order)
{
$user_sing = new UserSign();
if ($order['uid'] > 0 ) {
if ($order['uid'] > 0) {
$user_number = bcmul($order['refund_price'], '0.10', 2);
$sing = [
'uid' => $order['uid'],
@ -491,18 +502,21 @@ class PayNotifyLogic extends BaseLogic
'number' => $user_number,
];
$user_sing->save($sing);
$now_int = User::where('id',$order['uid'])->find();
if($now_int){
if($now_int['integral'] > $user_number){
User::where('id',$order['uid'])->dec('integral',$user_number)->update();
}else{
User::where('id',$order['uid'])->dec('integral',$now_int['integral'])->update();
//删除之前获得的兑换券
UserSign::where([
'order_id' => $order['order_id'],
'financial_pm' => 1,
])->update(['delete_time' => time()]);
$now_int = User::where('id', $order['uid'])->withTrashed()->find();
if ($now_int) {
if ($now_int['integral'] > $user_number) {
User::where('id', $order['uid'])->withTrashed()->dec('integral', $user_number)->update();
} else {
User::where('id', $order['uid'])->withTrashed()->dec('integral', $now_int['integral'])->update();
}
}
}
return true;
}
@ -605,7 +619,7 @@ class PayNotifyLogic extends BaseLogic
public static function dealRechargeFrozen($order)
{
$total_vip = bcmul($order['price'],0.1,2);
$total_vip = bcmul($order['price'], 0.1, 2);
$user_sing = new UserSign();
$sing = [
'uid' => $order['uid'],
@ -618,8 +632,8 @@ class PayNotifyLogic extends BaseLogic
'number' => $total_vip,
'back_num' => $total_vip,
];
$user_sing->save($sing);
User::where('id',$order->uid)->inc('integral',$total_vip)->update();
$user_sing->save($sing);
User::where('id', $order->uid)->inc('integral', $total_vip)->update();
return true;
}
@ -647,31 +661,30 @@ class PayNotifyLogic extends BaseLogic
$user = User::where('id', $uid)->findOrEmpty();
//用户的财务add
$capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price);
$capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price, [], 1);
if ($user->isEmpty()) {
return true;
}
bcscale(2);
// $user->now_money = bcadd($user->now_money, $price, 2);//v.1
$check = UserSign::where(['uid'=>$order->uid,'type'=>1])->count();
if(empty($check) && $user['user_ship'] == 0){
$check = UserSign::where(['uid' => $order->uid, 'type' => 1])->count();
if (empty($check) && $user['user_ship'] == 0) {
self::dealRechargeFrozen($order);
}
//更新等级
$user->user_ship = $order['user_ship'];
$user->purchase_funds = bcadd($user->purchase_funds, $price, 2);
$user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2);
$user->save();
if($order['other_uid']>0){
$uid=$order['other_uid'];
if ($order['other_uid'] > 0) {
$uid = $order['other_uid'];
}
PushService::push('wechat_mmp_' . $uid, $uid, ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]);
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]);
PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]);
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]);
if (!empty($extra['payer']['openid'])) {
Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4);
}
@ -695,6 +708,9 @@ class PayNotifyLogic extends BaseLogic
throw new \Exception('订单保存出错');
}
self::afterPay($order);
if ($order['is_storage'] == 1) {
UserProductStorageLogic::add($order);
}
$cashFlowLogic = new CashFlowLogic();
$cashFlowLogic->insert($order['store_id'], $order['pay_price']);
self::dealProductLog($order);
@ -731,6 +747,7 @@ class PayNotifyLogic extends BaseLogic
if ($order->pay_type == 9) {
$order->status = 2;
self::afterPay($order);
UserProductStorageLogic::add($order);
}
self::dealProductLog($order);
if ($order['shipping_type'] == 3) {
@ -758,6 +775,9 @@ class PayNotifyLogic extends BaseLogic
$financeLogic = new StoreFinanceFlowLogic();
$user_sing = new UserSign();
$off_activity = Config::where('name', 'off_activity')->value('value');
$village_uid = 0;
$brigade_uid = 0;
$user_ship = 0;
if ($off_activity == 1) {
//-----活动价结算更改
$financeLogic->order = $order;
@ -766,7 +786,7 @@ class PayNotifyLogic extends BaseLogic
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
$financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
$financeLogic->save();
if ($order['uid'] > 0 && $order['total_price'] >= 500 ) {
if ($order['uid'] > 0 && $order['total_price'] >= 500 && $order['pay_type'] !=PayEnum::PURCHASE_FUNDS) {
$user_number = bcmul($order['pay_price'], '0.10', 2);
$sing = [
'uid' => $order['uid'],
@ -780,28 +800,19 @@ class PayNotifyLogic extends BaseLogic
}
return false;
}
$vipFen = 0;
if ($order['uid'] > 0) {
// 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去
//用户下单该用户等级为1得时候才处理冻结金额
$user = User::where('id', $order['uid'])->find();
$user_ship = $user['user_ship'];
//纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额)
if ($order['spread_uid'] > 0) {
$oldUser = User::where('id', $order['spread_uid'])->field('purchase_funds,user_ship')->find();
if ($oldUser && $oldUser['user_ship'] == 1) {
if ($oldUser['purchase_funds'] < $order['pay_price']) {
$vipFen = $oldUser['purchase_funds'];
}
}
} elseif ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) {
if ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) {
$vipFrozenAmount = self::dealFrozenPrice($order['id']);
//为1的时候要去减活动价
// $final_price = bcsub($order['pay_price'],$order['deduction_price'],2);
// d($final_price,$vipFrozenAmount);
$order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2);
self::dealVipAmount($order, $order['pay_type']);
}
if($order['total_price'] >= 500 ){
if($order['total_price'] >= 500 && $order['pay_type'] !=PayEnum::PURCHASE_FUNDS){
$user_number = bcmul($order['pay_price'], '0.10', 2);
$sing = [
'uid' => $order['uid'],
@ -814,158 +825,41 @@ class PayNotifyLogic extends BaseLogic
];
$user_sing->save($sing);
}
// User::where('id', $order['uid'])->inc('integral', $user_number)->update();
}
$financeLogic->order = $order;
$financeLogic->user = ['uid' => $order['uid']];
// if ($order->pay_type != 9 || $order->pay_type != 10) {
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付
$count_frees = 0;
//平台手续费
$fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2);
$count_frees = bcadd($count_frees, $fees, 2);
if ($fees > 0) {
$financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费
$financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出
//查询用户对应的村长和队长
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
if ($address) {
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($arr1) {
$village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
}
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
if ($arr2) {
$brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
}
}
// $frozen = bcsub($order->profit, $fees, 2);
//缴纳齐全了就加商户没有就加到平台
$money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find();
$deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度
$store_profit = bcdiv(bcmul($order['pay_price'], '0.05', 2), 1, 2);
$count_frees = bcadd($count_frees, $store_profit, 2);
if ($deposit > 0) {
if ($deposit > $store_profit) {
if ($store_profit > 0) {
// SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $store_profit)->update();
$financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
$financeLogic->in($transaction_id, 0, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费
}
} else {
$money = bcsub($store_profit, $deposit, 2);
if ($deposit > 0) {
// SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $deposit)->update();
$financeLogic->out($transaction_id, $deposit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
}
if ($money) {
// SystemStore::where('id', $order['store_id'])->inc('store_money', $money)->update();
$financeLogic->in($transaction_id, $money, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费
}
if ($order['spread_uid'] > 0 || $user_ship>0) {
if($order['spread_uid'] > 0 && $user_ship == 0){
$user_ship = User::where('id', $order['spread_uid'])->value('user_ship');
}
switch ($user_ship) {
case 1: // 行业会员
case 4: // 商户
CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id);
break;
case 2: // 村长
CommissionLogic::setVillage($order, $village_uid, $brigade_uid, $transaction_id);
break;
case 3: // 队长
CommissionLogic::setBrigade($order, $village_uid, $brigade_uid, $transaction_id);
break;
default:
CommissionLogic::setStore($order, $transaction_id);
break;
}
} else {
if ($store_profit > 0) {
// SystemStore::where('id', $order['store_id'])->inc('store_money', $store_profit)->update();
$financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费
}
CommissionLogic::setStore($order, $transaction_id);
}
// if ($order['is_vip'] >= 1) {
if ($order['spread_uid'] > 0) {
if ($vipFen) {
$fees = bcdiv(bcmul($vipFen, '0.08', 2), 1, 2);
} else {
$fees = bcdiv(bcmul($order['pay_price'], '0.08', 2), 1, 2);
}
$count_frees = bcadd($count_frees, $fees, 2);
}
$fees = bcdiv(bcmul($order['pay_price'], '0.01', 2), 1, 2);
$count_frees = bcadd($count_frees, bcmul($fees, 3, 2), 2);
$village_uid = 0;
$brigade_uid = 0;
//查询用户对应的村长和队长
if ($order['uid'] > 0) {
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
if ($address) {
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($arr1) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id');
if ($uid) {
// User::where('id', $uid)->inc('integral', $fees)->update();
$village_uid = $uid;
}
}
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
if ($arr2) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id');
if ($uid) {
// User::where('id', $uid)->inc('integral', $fees)->update();
$brigade_uid = $uid;
}
}
}
}
if ($fees > 0) {
//村长获得
// $sing = [];
// $sing[] = [
// 'uid' => $village_uid,
// 'order_id' => $order['order_id'],
// 'title' => '村长订单获得兑换券',
// 'store_id' => $order['store_id'],
// 'number' => $fees,
// 'financial_pm' => 1,
// 'user_ship' => 2,
// ];
// $sing[] = [
// 'uid' => $brigade_uid,
// 'order_id' => $order['order_id'],
// 'title' => '队长订单获得兑换券',
// 'store_id' => $order['store_id'],
// 'number' => $fees,
// 'financial_pm' => 1,
// 'user_ship' => 3,
// ];
// $sing[] = [
// 'uid' => $village_uid,
// 'order_id' => $order['order_id'],
// 'title' => '订单扣除兑换券',
// 'store_id' => $order['store_id'],
// 'number' => $fees,
// 'financial_pm' => 0,
// 'user_ship' => 2,
// ];
// $sing[] = [
// 'uid' => $brigade_uid,
// 'order_id' => $order['order_id'],
// 'title' => '订单扣除兑换券',
// 'store_id' => $order['store_id'],
// 'number' => $fees,
// 'financial_pm' => 0,
// 'user_ship' => 3,
// ];
if ($village_uid > 0) {
// SystemStore::where('id', $village_uid)->inc('store_money', $fees)->update();
$financeLogic->other_arr['vip_uid'] = $village_uid;
}
$financeLogic->in($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
//队长获得
if ($brigade_uid > 0) {
// SystemStore::where('id', $brigade_uid)->inc('store_money', $fees)->update();
$financeLogic->other_arr['vip_uid'] = $brigade_uid;
}
$financeLogic->in($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
// $user_sing->saveAll($sing);
//其他获得
$financeLogic->other_arr['vip_uid'] = 0;
$financeLogic->in($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
}
// }
$fees = bcsub($order['pay_price'], $count_frees, 2);
//供应链订单获得
if ($fees > 0) {
$financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
}
// }
$financeLogic->save();
// }
}
/**

View File

@ -27,9 +27,9 @@ class StoreFinanceFlowLogic extends BaseLogic
* @param $staffId
* @param $status
*/
public function out($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1,$pay_type=7)
public function out($transaction_id, $number, $financialType, $storeId = 0, $staffId = 0, $status = 1, $pay_type = 7)
{
$this->setData($number, $financialType, 0, $storeId, $staffId, $status,$transaction_id,$pay_type);
$this->setData($number, $financialType, 0, $storeId, $staffId, $status, $transaction_id, $pay_type);
}
/**
@ -41,22 +41,22 @@ class StoreFinanceFlowLogic extends BaseLogic
* @param $staffId
* @param $status
*/
public function in($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1,$pay_type=7)
public function in($transaction_id, $number, $financialType, $storeId = 0, $staffId = 0, $status = 1, $pay_type = 7)
{
$this->setData($number, $financialType, 1, $storeId, $staffId, $status,$transaction_id,$pay_type);
$this->setData($number, $financialType, 1, $storeId, $staffId, $status, $transaction_id, $pay_type);
}
public function setData($number, $financialType, $pm, $storeId, $staffId, $status,$transaction_id,$pay_type=7)
public function setData($number, $financialType, $pm, $storeId, $staffId, $status, $transaction_id, $pay_type = 7)
{
if (empty($this->financeSn)) {
$this->financeSn = $this->getSn();
}
$data=[
$data = [
'order_id' => $this->order['id'],
'transaction_id' => $transaction_id,
'order_sn' => $this->order['order_id'],
'user_id' => $this->user['uid']??0,
'other_uid' => $this->other_arr['vip_uid']??0,
'user_id' => $this->user['uid'] ?? 0,
'other_uid' => $this->other_arr['vip_uid'] ?? 0,
'financial_type' => $financialType,
'financial_pm' => $pm,
'number' => $number,
@ -65,22 +65,22 @@ class StoreFinanceFlowLogic extends BaseLogic
'store_id' => $storeId !== '' ? $storeId : $this->order['store_id'],
'staff_id' => $staffId !== '' ? $staffId : $this->order['staff_id'],
'financial_record_sn' => $this->financeSn . ($this->index++),
'create_time'=>time()
'create_time' => time()
];
switch($financialType){
switch ($financialType) {
case OrderEnum::MERCHANT_ORDER_OBTAINS: // 商户
case OrderEnum::ORDER_MARGIN: // 商户保证金
$data['type'] =OrderEnum::MERCHANT;
$data['type'] = OrderEnum::MERCHANT;
break;
case OrderEnum::PLATFORM_ORDER_OBTAINS: // 平台
case OrderEnum::ORDER_HANDLING_FEES: // 手续费
$data['type'] =OrderEnum::PLATFORM;
$data['type'] = OrderEnum::PLATFORM;
break;
case OrderEnum::SUPPLIER_ORDER_OBTAINS: // 供应链
$data['type'] =OrderEnum::SUPPLIER;
case OrderEnum::SUPPLIER_ORDER_OBTAINS: // 供应链
$data['type'] = OrderEnum::SUPPLIER;
break;
default: // 用户
$data['type'] =OrderEnum::USER;
$data['type'] = OrderEnum::USER;
break;
}
$this->list[] = $data;
@ -131,25 +131,33 @@ class StoreFinanceFlowLogic extends BaseLogic
/**
* 核销后更新用户余额
*/
public function updateStatusUser($id,$uid,$money,$order_id){
public function updateStatusUser($id, $uid, $money, $order_id)
{
StoreFinanceFlow::where('id', $id)->update(['status' => 1]);
$find=User::where('id',$uid)->find();
$find = User::where('id', $uid)->find();
$capitalFlowDao = new CapitalFlowLogic($find);
$capitalFlowDao->userIncome('system_balance_add', 'order', $order_id, $money);
$find->inc('now_money',$money)->update();
$find->inc('now_money', $money)->update();
}
/**
* 核销后更新门店余额
*/
public function updateStatusStore($order_id,$store_id,$money,$deposit){
StoreFinanceFlow::where(['order_id'=>$order_id,'financial_pm'=>1,'financial_type'=>11])->update(['status' => 1]);
StoreFinanceFlow::where(['order_id'=>$order_id,'financial_pm'=>1,'financial_type'=>2])->update(['status' => 1]);
if($money){
public function updateStatusStore($order_id, $store_id, $money, $deposit)
{
StoreFinanceFlow::where(['order_id' => $order_id,'financial_type' => 11])->update(['status' => 1]);
StoreFinanceFlow::where(['order_id' => $order_id,'financial_type' => 2])->update(['status' => 1]);
if ($money>0) {
SystemStore::where('id', $store_id)->inc('store_money', $money)->update();
}
if($deposit){
if ($deposit>0) {
SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update();
}
$find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16,'status'=>0])->find();
StoreFinanceFlow::where(['order_id' => $order_id,'financial_type' => 16])->update(['status' => 1]);
if ($find) {
if ($find['number'] > 0) {
SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update();
}
}
}
}

View File

@ -6,11 +6,18 @@ use app\common\logic\BaseLogic;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\user_product_storage\UserProductStorage;
use app\common\model\user_product_storage_log\UserProductStorageLog;
use think\facade\Db;
/**
* 用户商品储存逻辑
*/
class UserProductStorageLogic extends BaseLogic
{
/**
* 入库逻辑处理
*/
public static function add($order){
$arr=StoreOrderCartInfo::where('oid',$order['id'])->field('product_id,cart_num nums')->select();
$arr=StoreOrderCartInfo::where('oid',$order['id'])->field('product_id,cart_num nums')->select()->toArray();
if($arr){
$data=$arr;
$data_log=$arr;
@ -23,10 +30,46 @@ class UserProductStorageLogic extends BaseLogic
$data_log[$k]['oid']=$order['id'];
$data_log[$k]['financial_pm']=1;
}
UserProductStorage::insertAll($data);
UserProductStorageLog::insertAll($data_log);
(new UserProductStorage())->saveAll($data);
(new UserProductStorageLog())->saveAll($data_log);
}
}
/**
* 出库
*/
public static function supply($data,$uid,$store_id){
Db::startTrans();
try {
$data_log=[];
foreach ($data as $k=>$v){
$find=UserProductStorage::where('uid',$uid)->where('product_id',$v['product_id'])->find();
if($find){
if($find['nums']<$v['nums']){
self::setError('库存不足');
return false;
}
$nums=bcsub($find['nums'],$v['nums']);
$find->nums=$nums;
if($nums==0){
$find->status=0;
}
$find->save();
$data_log[$k]['uid']=$uid;
$data_log[$k]['oid']=$find['oid'];
$data_log[$k]['product_id']=$find['product_id'];
$data_log[$k]['store_id']=$store_id;
$data_log[$k]['financial_pm']=0;
$data_log[$k]['nums']=$v['nums'];
}
}
(new UserProductStorageLog())->saveAll($data_log);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -310,8 +310,8 @@ class StoreOrderController extends BaseAdminController
public function writeoff_order()
{
$params = (new OrderValidate())->post()->goCheck('check');
$count = StoreOrder::where('verify_code', $params['verify_code'])->count();
if (empty($count)) {
$count = StoreOrder::where('verify_code', $params['verify_code'])->whereIn('status',[0,1])->where('refund_status',0)->find();
if (!$count) {
return $this->fail('无该核销码请检查');
}
$params['store_id'] = $this->adminInfo['store_id'];

View File

@ -0,0 +1,45 @@
<?php
namespace app\store\controller\user_product_storage;
use app\store\controller\BaseAdminController;
use app\admin\lists\user_product_storage\UserProductStorageLists;
use app\common\logic\user_product_storage\UserProductStorageLogic;
/**
* 用户商品储存控制器
* Class UserProductStorageController
* @package app\admin\controller\user_product_storage
*/
class UserProductStorageController extends BaseAdminController
{
/**
* @notes 获取用户商品储存列表
* @return \think\response\Json
* @author admin
* @date 2024/06/28 11:05
*/
public function lists()
{
return $this->dataLists(new UserProductStorageLists());
}
/**
* 出库
*/
public function supply(){
$params=$this->request->post();
$info=$params['info'];
$uid=$params['uid'];
$store_id=$this->adminInfo['store_id'];
UserProductStorageLogic::supply($info,$uid,$store_id);
if(UserProductStorageLogic::hasError()){
return $this->fail(UserProductStorageLogic::getError());
}
return $this->success('操作成功');
}
}

View File

@ -22,7 +22,7 @@ class UserLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['id','user_ship'],
'=' => ['id','user_ship','store_id'],
'%like%' => ['mobile'],
];
}

View File

@ -58,12 +58,14 @@ class WorkbenchLogic extends BaseLogic
$cashFinanceWhere = [];
$storeFinanceWhere = ['financial_type'=>2,'financial_pm'=>1];
$storeFinanceWhereTwo = ['financial_type'=>11,'financial_pm'=>0];
$attritionWhere=[];
if ($params['store_id'] != 0) {
$where['store_id'] = $params['store_id'];
$userRechargeWhere['store_id'] = $params['store_id'];
$cashFinanceWhere = ['store_id' => $params['store_id']];
$storeFinanceWhere['store_id'] = $params['store_id'];
$storeFinanceWhereTwo['store_id'] = $params['store_id'];
$attritionWhere['store_id'] = $params['store_id'];
}
$orderLogic = new StoreOrderLogic();
//订单总金额
@ -89,6 +91,8 @@ class WorkbenchLogic extends BaseLogic
// $data['receipt_amount'] = UserRecharge::where($userRechargeWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('price');
//保证金金额
$data['deposit_amount'] = StoreFinanceFlow::where($storeFinanceWhereTwo)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number');
/**门店损耗金 */
$data['attrition_amount'] = SystemStore::where($attritionWhere)->sum('attrition');
//门店成交用户数
$data['user_number'] = StoreOrder::where($where)
->whereBetweenTime('pay_time', $startTime, $endTime)