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

Reviewed-on: #24
This commit is contained in:
mkm 2024-06-27 21:17:17 +08:00
commit c798b5f657
31 changed files with 1712 additions and 183 deletions

View File

@ -46,7 +46,7 @@ class StoreFinanceFlowDayLists extends BaseAdminDataLists implements ListsSearch
return StoreFinanceFlow::where($this->searchWhere)
->field('
FROM_UNIXTIME(create_time, "%Y-%m-%d") as date,
SUM(CASE WHEN financial_pm = 1 THEN number ELSE 0 END) as income,
SUM(CASE WHEN financial_pm = 1 AND financial_type = 1 THEN number ELSE 0 END) as income,
SUM(CASE WHEN financial_pm = 0 THEN number ELSE 0 END) as expenditure
')
->limit($this->limitOffset, $this->limitLength)

View File

@ -32,7 +32,7 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt
public function setSearch(): array
{
return [
'=' => ['store_id', 'user_id', 'create_time', 'staff_id'],
'=' => ['store_id', 'user_id', 'create_time', 'staff_id','financial_type','financial_pm','order_id'],
'between_time' => 'create_time',
'%pipe_like%' => ['keyword' => 'order_sn'],
];
@ -53,18 +53,24 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt
$field = [
'id', 'order_id', 'order_sn', 'create_time', 'other_uid', 'user_id', 'store_id', 'staff_id', 'financial_type', 'financial_pm', 'pay_type', 'type', 'number', 'status'
];
$this->searchWhere[] = ['financial_type', '=', 1];
$this->searchWhere[] = ['financial_pm', '=', 1];
if($this->request->get('order_id')){
$order=['financial_pm'=>'desc'];
}else{
$order=['id'=>'desc'];
}
$data = StoreFinanceFlow::where($this->searchWhere)
->field($field)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->order($order)
->select()->each(function ($item) {
if ($item['user_id'] <= 0) {
$item['nickname'] = '游客';
} else {
$id = $item['user_id'];
$item['nickname'] = User::where('id', $item['user_id'])->value('nickname') . "|$id";
$user=User::where('id', $item['user_id'])->field('real_name,nickname')->find();
if($user){
$item['nickname'] =$user['real_name']!=''?$user['real_name']:$user['nickname'].'|'.$id;
}
}
if (!empty($this->request->adminInfo['store_id'])) {
$item['financial_pm'] = $item['financial_pm'] == 0 ? 1 : 0;

View File

@ -46,7 +46,7 @@ class StoreFinanceFlowMonthLists extends BaseAdminDataLists implements ListsSear
return StoreFinanceFlow::where($this->searchWhere)
->field('
CONCAT(YEAR(FROM_UNIXTIME(create_time, "%Y-%m-%d")), "", MONTH(FROM_UNIXTIME(create_time, "%Y-%m-%d")), "") as date,
SUM(CASE WHEN financial_pm = 1 THEN number ELSE 0 END) as income,
SUM(CASE WHEN financial_pm = 1 AND financial_type = 1 THEN number ELSE 0 END) as income,
SUM(CASE WHEN financial_pm = 0 THEN number ELSE 0 END) as expenditure
')
->limit($this->limitOffset, $this->limitLength)

View File

@ -46,7 +46,7 @@ class StoreFinanceFlowWeekLists extends BaseAdminDataLists implements ListsSearc
return StoreFinanceFlow::where($this->searchWhere)
->field('
CONCAT("", LPAD(YEAR(FROM_UNIXTIME(create_time, "%Y-%m-%d")), 4, "0"), "-", LPAD(WEEK(FROM_UNIXTIME(create_time, "%Y-%m-%d"), 3), 2, "0"), "周(", LPAD(MONTH(FROM_UNIXTIME(create_time, "%Y-%m-%d")), 2, "0"), "月)") as date,
SUM(CASE WHEN financial_pm = 1 THEN number ELSE 0 END) as income,
SUM(CASE WHEN financial_pm = 1 AND financial_type = 1 THEN number ELSE 0 END) as income,
SUM(CASE WHEN financial_pm = 0 THEN number ELSE 0 END) as expenditure
')
->limit($this->limitOffset, $this->limitLength)

View File

@ -10,6 +10,7 @@ use app\common\model\store_order\StoreOrder;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\user\User;
/**
* 订单列表列表
@ -29,7 +30,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['order_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id'],
'=' => ['order_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff'],
'between_time' => 'create_time'
];
}
@ -46,7 +47,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function lists(): array
{
return StoreOrder::with(['user', 'staff'])->where($this->searchWhere)
return StoreOrder::with(['staff'])->where($this->searchWhere)
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->request->adminInfo['store_id']);
})
@ -58,20 +59,29 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
$query->whereIn('status', $status);
}
})
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status'])
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
$item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : '';
$item['status_name'] = OrderEnum::getOrderType($item['status']) ?? '';
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;
}
}
if ($item['paid'] == 0) {
$item['status_name'] = '待支付';
}
$product = StoreOrderCartInfo::where('oid', $item['id'])->field(['id', 'oid', 'product_id', 'cart_info'])
->limit(3)->select();
foreach ($product as &$items) {
$items['store_name'] = $items['cart_info']['name'];
$items['image'] = $items['cart_info']['image'];
$items['store_name'] = $items['cart_info']['name']??'';
$items['image'] = $items['cart_info']['image']??'';
}
$item['product'] = $product;
return $item;

View File

@ -58,15 +58,14 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
}
}
return StoreProduct::where($this->searchWhere)
->field(['id', 'image', 'store_name','swap', 'cate_id','batch', 'price','vip_price','sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase','bar_code','manufacturer_information'])
->field(['id', 'image', 'store_name','swap','product_type','cate_id','batch', 'price','vip_price','sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase','bar_code','manufacturer_information'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
return $item;
})
->toArray();
})?->toArray();
}

View File

@ -6,7 +6,7 @@ namespace app\admin\lists\user_label;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\user_label\UserLabel;
use app\common\lists\ListsSearchInterface;
use app\common\model\user\UserShip;
/**
* 用户标签列表
@ -42,11 +42,14 @@ class UserLabelLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function lists(): array
{
$limit=UserShip::where('id',1)->value('limit');
return UserLabel::where($this->searchWhere)
->field(['label_id', 'label_name'])
->limit($this->limitOffset, $this->limitLength)
->order(['label_id' => 'desc'])
->select()
->select()->each(function ($item) use($limit){
$item->limit = $limit;
})
->toArray();
}

View File

@ -19,7 +19,7 @@ use app\common\model\auth\Admin;
use app\admin\service\AdminTokenService;
use app\common\model\auth\AdminRole;
use app\common\service\FileService;
use app\MyBusinessException;
use Exception;
use think\facade\Db;
use Webman\Config;
@ -44,6 +44,9 @@ class LoginLogic extends BaseLogic
{
$time = time();
$admin = Admin::where('account', '=', $params['account'])->find();
if(!$admin) {
throw new Exception('账号不存在');
}
//用户表登录信息更新
$admin->login_time = $time;
$admin->login_ip = request()->getLocalIp();

View File

@ -127,6 +127,33 @@ class StoreProductLogic extends BaseLogic
}
}
/*
* 传入三级或者二级分类返还上级分类 一级那全是相同
*/
public static function dealChangeCate($cate_id)
{
$value =[];
$last_cate = Db::name('store_category')->where('id',$cate_id)->value('pid');
if(!empty($last_cate)){
//2
$value['two_cate_id'] = $last_cate;
//1
$first_cate = Db::name('store_category')->where('id',$value['two_cate_id'])->value('pid');
if(empty($first_cate)){//顶级了
$value['two_cate_id'] = $cate_id;
$value['top_cate_id'] = $last_cate;
}else{
$value['top_cate_id'] = $first_cate;
}
}else{
//1-2 选的1级目录
$value['two_cate_id'] = $cate_id;
$value['top_cate_id'] = $cate_id;
}
return $value;
}
/**
* @notes 编辑商品列表
* @param array $params
@ -175,15 +202,15 @@ class StoreProductLogic extends BaseLogic
self::updateGoodsclass($params['cate_id'], $value['store_id']);
}
}*/
$dealCate = self::dealChangeCate($params['cate_id']);
//修改
StoreBranchProduct::where('product_id', $params['id'])->update([
'price' => $params['price'], 'vip_price' => $params['vip_price'],
'cost' => $params['cost'],'unit'=>$params['unit'],
'batch'=>$params['batch'],'store_name'=>$params['store_name'],
'manufacturer_information' => $params['manufacturer_information']??'',
'store_info' => $params['store_info']??'',
'store_info' => $params['store_info']??'','cate_id'=>$params['cate_id'],
'top_cate_id'=>$dealCate['top_cate_id'],'two_cate_id'=>$dealCate['two_cate_id']
]);
Db::commit();
@ -283,6 +310,7 @@ class StoreProductLogic extends BaseLogic
$attr_value = StoreProductAttrValue::where('product_id', $id)->findOrEmpty();
Db::startTrans();
try {
$dealCate = self::dealChangeCate($find['cate_id']);
$product = [
'product_id' => $find['id'],
'image' => $find['image'],
@ -291,6 +319,8 @@ class StoreProductLogic extends BaseLogic
'keyword' => $find['keyword'],
'bar_code' => $find['bar_code'],
'cate_id' => $find['cate_id'],
'top_cate_id' => $dealCate['top_cate_id'],
'two_cate_id' => $dealCate['two_cate_id'],
'price' => $find['price'],
'unit' => $find['unit'],
'store_id' => $store_id,

View File

@ -89,7 +89,6 @@ class UserLogic extends BaseLogic
'account' => $params['mobile'],
'password' => $password,
'mobile' => $params['mobile'],
'user_ship' => $params['user_ship']??0,
'label_id' => $params['label_id']??0,
];

View File

@ -0,0 +1,71 @@
<?php
namespace app\admin\middleware;
use Exception;
use ReflectionClass;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;
class OperationLogMiddleware implements MiddlewareInterface
{
public function process(Request $request, callable $handler): Response
{
//需要登录的接口,无效访问时不记录
if (!$request->controllerObject->isNotNeedLogin() && empty($request->adminInfo)) {
return $handler($request);
}
//不记录日志操作
if (strtolower(str_replace('.', '\\', $request->controller)) === 'setting\system\log') {
return $handler($request);
}
//获取操作注解
$notes = '';
try {
$re = new ReflectionClass($request->controllerObject);
$doc = $re->getMethod($request->action)->getDocComment();
if (empty($doc)) {
throw new Exception('请给控制器方法注释');
}
preg_match('/\s(\w+)/u', $re->getMethod($request->action)->getDocComment(), $values);
$notes = $values[0];
} catch (Exception $e) {
$notes = $notes ?: '无法获取操作名称,请给控制器方法注释';
}
$params = $request->all();
//过滤密码参数
if (isset($params['password'])) {
$params['password'] = "******";
}
//过滤密钥参数
if(isset($params['app_secret'])){
$params['app_secret'] = "******";
}
//导出数据操作进行记录
if (isset($params['export']) && $params['export'] == 2) {
$notes .= '-数据导出';
}
//记录日志
$systemLog = new \app\common\model\OperationLog();
$systemLog->admin_id = $request->adminInfo['admin_id'] ?? 0;
$systemLog->admin_name = $request->adminInfo['name'] ?? '';
$systemLog->action = $notes;
$systemLog->account = $request->adminInfo['account'] ?? '';
$systemLog->url = $request->url(true);
$systemLog->type = $request->post()?'POST':'GET';
$systemLog->params = json_encode($params, true);
$systemLog->ip = $request->getRemoteIp();
// $systemLog->result = $response->getContent();
$systemLog->save();
return $handler($request);
}
}

View File

@ -32,53 +32,7 @@ class IndexController extends BaseApiController
public function index()
{
$config = [
// HTTP 请求的超时时间(秒)
'timeout' => 5.0,
// 默认发送配置
'default' => [
// 网关调用策略,默认:顺序调用
'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,
// 默认可用的发送网关
'gateways' => [
'yunpian', 'aliyun',
],
],
// 可用的网关配置
'gateways' => [
'errorlog' => [
'file' => runtime_path() . '/logs/' . date('Ymd') . '/easy-sms.log',
],
'aliyun' => [
'access_key_id' => 'LTAI5t7mhH3ij2cNWs1zhPmv',
'access_key_secret' => 'gqo2wMpvi8h5bDBmCpMje6BaiXvcPu',
'sign_name' => '里海科技',
],
//...
],
];
try {
$easySms = new EasySms($config);
$template = getenv('SMS_TEMPLATE');
$a = $easySms->send(18715753257, [
'content' => '您的验证码为: 6379',
'template' => $template,
'data' => [
'code' => 6379
],
]);
// d($a);
}catch (NoGatewayAvailableException $exception){
throw new \Exception($exception->getExceptions());
}
d($a,getenv('SMS_TEMPLATE'));
return json([1]);
$all_where['paid'] = 1;
d(OrderLogic::dayPayPrice($all_where,date('Y-m-d',time())));

View File

@ -77,7 +77,7 @@ class LoginController extends BaseApiController
*/
public function updateUser()
{
$params = (new WechatLoginValidate())->post()->goCheck("updateUser");
$params = $this->request->post();
$result = LoginLogic::updateUser($params, $this->userId);
if ($result === false) {
return $this->fail(LoginLogic::getError());

View File

@ -77,13 +77,15 @@ class StoreController extends BaseApiController
return $this->fail('验证码错误');
}
}
$find=User::where('mobile',$params['mobile'])->find();
if($params['price']>10000){
return $this->fail('充值金额不能大于10000');
}
$find=User::where('account|mobile',$params['mobile'])->find();
if(!$find){
$params['create_uid']=$this->userId;
$find=UserUserLogic::StoreAdd($params);
}else{
$find['real_name']=$params['real_name'];
$find['user_ship']=$params['user_ship']??0;
$find['label_id']=$params['label_id']??0;
$find->save();
}
@ -99,8 +101,9 @@ class StoreController extends BaseApiController
'other_uid'=>$this->userId,
'staff_id'=>0,
'order_id'=>getNewOrderId('CZ'),
'price'=>Config::where('name','recharge')->value('value')??1000,
'price'=>$params['price']??1000,
'recharge_type'=>'INDUSTRYMEMBERS',
'user_ship'=>$params['user_ship']??0,
];
$order = UserRecharge::create($data);

View File

@ -6,6 +6,7 @@ namespace app\api\lists\cate;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\cate\Cate;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\Request;
use think\facade\Db;
@ -27,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['name', 'data', 'store_id', 'sort', 'pid'],
'=' => ['name', 'data', 'store_id', 'sort'],
];
}
@ -44,10 +45,24 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array
{
$level = Request()->get('level', 1);
$this->searchWhere[] = ['level', '=', $level];
$this->searchWhere[] = ['count', '>', 0];
$this->searchWhere[] = ['delete_time', '=', null];
$cate_arr = Db::name('store_product_cate')->where($this->searchWhere)->column('cate_id');
$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){
$this->searchWhere[] = ['two_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('cate_id');
}
$lists = [];
if ($cate_arr) {
return Cate::where('id', 'in', $cate_arr)
@ -56,18 +71,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
->order(['sort' => 'desc', 'id' => 'desc'])
->select()->toArray();
}
// ->each(function ($item) {
// $a = Goodsclass::where('pid', $item['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select();
// $item['children'] = $a;
// foreach ($a as $k => &$v) {
// $b = Goodsclass::where('pid', $v['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select();
// $v['children'] = $b;
// }
// })->toArray();
return $lists;
// return linear_to_tree($lists, 'children');
}
@ -80,8 +84,24 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function count(): int
{
$level = Request()->get('level', 1);
$pid = $this->request->get('pid',0);
if($pid == 0 && $level ==1){
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('top_cate_id');
}
return Db::name('store_product_cate')->where($this->searchWhere)
->count();
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){
$this->searchWhere[] = ['two_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('cate_id');
}
return Cate::where('id', 'in', $cate_arr)->count();
}
}

View File

@ -108,14 +108,16 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
$data= [
'off_activity' => $this->off_activity,
'total_price' => $this->total_price,
'msg' => '',
'msg' => '您已选购满500元支付成功后即可获得'.bcmul($this->total_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。',
'pay_price' => $this->total_price
];
if($this->off_activity==1){
$data['pay_price']=$this->activity_price;
if($this->activity_price<500){
$data['msg']='还差'.bcsub(500,$this->activity_price,2).'元可获得10%品牌礼品券';
$data['msg']='还差'.bcsub(500,$this->activity_price,2).'即可获得10%的品牌礼品兑换券,可到线下门店兑换礼品。';
$data['pay_price']= $this->activity_price;
}else{
$data['msg']= '您已选购满500元支付成功后即可获得'.bcmul($this->activity_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。';
}
}
return $data;

View File

@ -33,13 +33,10 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
public function setSearch(): array
{
return [
'=' => ['store_id', 'cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
];
return [
'=' => ['store_id', 'cate_id'],
'=' => ['store_id', 'cate_id','top_cate_id','two_cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
];
}
/**
* @notes 设置支持排序字段
@ -74,17 +71,17 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
*/
public function lists(): array
{
$class_all = $this->request->get('class_all');
if ($class_all) {
//查3级别的
$arr = Cate::where('pid', $class_all)->column('id');
if ($arr) {
$arr2 = Cate::where('pid', 'in', $arr)->column('id');
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
} else {
$this->searchWhere[] = ['cate_id', '=', $class_all];
}
}
// $class_all = $this->request->get('class_all');
// if ($class_all) {
// //查3级别的
// $arr = Cate::where('pid', $class_all)->column('id');
// if ($arr) {
// $arr2 = Cate::where('pid', 'in', $arr)->column('id');
// $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
// } else {
// $this->searchWhere[] = ['cate_id', '=', $class_all];
// }
// }
$order = $this->request->get('order','');
$field = $this->request->get('field','');
if(empty($order)||empty($field)){
@ -92,7 +89,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
}else{
$order = [$field => $order];
}
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch';
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id';
$this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[] = ['stock', '>', 0];

View File

@ -441,20 +441,22 @@ class LoginLogic extends BaseLogic
*/
public static function updateUser($params, $userId)
{
$find=User::where(['mobile' =>$params['mobile']])->find();
if($find){
$auth=UserAuth::where(['user_id'=>$find['id']])->find();//别人的
if($auth){
self::$error ='该手机号已绑定';
return false;
}else{
UserAuth::where(['user_id'=>$userId])->update(['user_id'=>$find['id']]);
$data=['is_new_user' => YesNoEnum::NO];
if(isset($params['mobile']) && $params['mobile']!=''){
$data['mobile']=$params['mobile'];
$find=User::where(['mobile' =>$params['mobile']])->find();
if($find){
$auth=UserAuth::where(['user_id'=>$find['id']])->find();//别人的
if($auth){
self::$error ='该手机号已绑定';
return false;
}else{
UserAuth::where(['user_id'=>$userId])->update(['user_id'=>$find['id']]);
}
}
}
$data=[
'mobile'=>$params['mobile'],
'is_new_user' => YesNoEnum::NO
];
if(!empty($params['nickname'])){
$data['nickname'] = $params['nickname'];
}

View File

@ -15,6 +15,7 @@ use app\common\model\dict\DictData;
use app\common\model\dict\DictType;
use app\common\model\order\Cart;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
@ -405,10 +406,11 @@ class OrderLogic extends BaseLogic
*/
public static function writeOff($params): bool
{
$data = StoreOrder::with('store')->where([
$order = StoreOrder::with('store')->where([
'verify_code' => $params['verify_code']
])->find();
if (empty($data)) {
if (empty($order)) {
self::setError('订单不存在');
return false;
}
Db::startTrans();
@ -420,7 +422,7 @@ class OrderLogic extends BaseLogic
'update_time' => time(),
'store_id' => $params['store_id'],
'staff_id' => $params['staff_id']??0,
], ['id' => $data['id']]);
], ['id' => $order['id']]);
(new StoreOrderCartInfo())->update([
'verify_code'=>$params['verify_code'].'-1',
'writeoff_time' => time(),
@ -428,20 +430,90 @@ class OrderLogic extends BaseLogic
'store_id' => $params['store_id'],
'staff_id' => $params['staff_id']??0,
'update_time' => time(),
], ['oid' => $data['id']]);
], ['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']);
// }
$order=StoreOrder::where('id',$data['id'])->find();
// PayNotifyLogic::afterPay($order);
PayNotifyLogic::descStock($order['id']);
if($order['uid'] && $order['total_price'] >= 500){
$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();
foreach($select_1 as $k=>$v){
$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);
User::where('id', $order['uid'])->inc('integral', $user_number)->update();
UserSign::where(['uid' => $order['uid'],'order_id' => $order['order_id']])->update(['status'=>1]);
}
if ($order['spread_uid'] > 0) {
$spread_find=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>12,'other_uid'=>$order['spread_uid']])->find();
if($spread_find){
$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');
$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;

View File

@ -91,7 +91,7 @@ class WechatLoginValidate extends BaseValidate
*/
public function sceneUpdateUser()
{
return $this->only(['mobile']);
return $this->only([]);
}

View File

@ -46,6 +46,7 @@ class OrderEnum
const CASHIER_FACE_PAY = 17;//现金收银
const PURCHASE_FUNDS = 18;//采购款收银
const USER_ORDER_REFUND = 19;//订单返还
const PAY_BACK =-1;
@ -165,11 +166,7 @@ class OrderEnum
self::ORDER_MARGIN=>'保证金',
self::VIP_ORDER_OBTAINS=>'会员',
self::OTHER_ORDER_OBTAINS=>'其他',
self::USER_ORDER_REFUND=>'订单返还'
];
if ($value === true) {

View File

@ -14,7 +14,6 @@ class CommissionLogic extends BaseLogic
*/
public static function setVillage($order, $transaction_id)
{
self::user($order, 0.05, $transaction_id,$order['uid'],14);
$village_uid=0;
$brigade_uid=0;
if ($order['uid'] > 0) {
@ -36,7 +35,8 @@ class CommissionLogic extends BaseLogic
}
}
}
self::user($order, 0.03, $transaction_id,$village_uid,12);//会员
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);//其他
}
@ -45,7 +45,6 @@ class CommissionLogic extends BaseLogic
*/
public static function setBrigade($order, $transaction_id)
{
self::user($order, 0.05, $transaction_id,$order['uid'],14);
$village_uid=0;
$brigade_uid=0;
if ($order['uid'] > 0) {
@ -67,8 +66,9 @@ class CommissionLogic extends BaseLogic
}
}
}
self::user($order, 0.03, $transaction_id,$village_uid,12);//会员
self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
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);//其他
}
/**
@ -76,7 +76,6 @@ class CommissionLogic extends BaseLogic
*/
public static function setCook($order, $transaction_id)
{
self::user($order, 0.07, $transaction_id,$order['uid'],12);//改到带返还金中
$village_uid=0;
$brigade_uid=0;
if ($order['uid'] > 0) {
@ -98,6 +97,7 @@ class CommissionLogic extends BaseLogic
}
}
}
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);//其他

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,8 @@ use app\common\model\user\UserAddress;
use app\common\model\user\UserRecharge;
use app\common\model\user\UserShip;
use app\common\model\user_sign\UserSign;
use app\common\model\vip_flow\VipFlow;
use app\common\service\Curl;
use app\common\service\PushService;
use support\Log;
use think\facade\Db;
@ -92,10 +94,18 @@ 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 = [
'verify_code' => $order['verify_code'],
'store_id' => $extra['store_id'],
'staff_id' => $extra['staff_id']
];
OrderLogic::writeOff($params);
}
// Redis::send('push-platform-print', ['id' => $order['id']], 60);
// PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
}
@ -186,6 +196,7 @@ class PayNotifyLogic extends BaseLogic
// self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS);
// }
// self::addUserSing($order);
self::afterPay($order);
if ($extra && $extra['store_id']) {
$params = [
'verify_code' => $order['verify_code'],
@ -195,14 +206,163 @@ 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);
// }
// if($order['shipping_type'] == 3){
// self::descStock($order['id']);
// }
self::afterPay($order);
// 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){
$query = UserSign::where([
'uid'=>$order['uid'],
'type'=>1,
'status'=>0
]);
// $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);
// 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;
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();
}
}
/* else{
//大于0的时候
//先处理金额大的再处理剩余的
//把所有的金额改为正的再加一条后再加
UserSign::where([
'uid'=>$order['uid'],
'type'=>1,
'status'=>0
])->update([
'status'=>1,
'title'=>json_encode($ids)
]);
if ($check >= $backPurchase) {
//补一条待解冻的
$left = bcsub($check,$backPurchase,2);
if($left > 0){
$data = [
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '补冻结兑换券',
'financial_pm' => 0,
'type' => 1,
];
$data['number'] =$check;
$sid = Db::name('user_sign')->insertGetId($data);
$data = [
'uid' => $order['uid'],
'sid' => $sid,
'order_id' => $order['order_id'],
'title' => '充值获得冻结兑换券',
'financial_pm' => 1,
'type' => 1,
];
$data['number'] =$backPurchase;
Db::name('user_sign_log')->insert($data);
}
// User::where('id',$order['uid'])->inc('purchase_funds',$backPurchase)->update();//add
}else{
//log
$data = [
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '充值获得冻结兑换券',
'financial_pm' => 1,
'type' => 1,
];
$data['number'] =$check;
Db::name('user_sign_log')->insert($data);
// User::where('id',$order['uid'])->inc('purchase_funds',$check)->update();//add
}
}*/
// }
return true;
}
return true;
}
/**
* @notes 微信通用回调
@ -280,7 +440,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();
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);
@ -290,7 +450,6 @@ class PayNotifyLogic extends BaseLogic
//退款
$capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money);
}
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款
$user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2);
$user->save();
@ -299,6 +458,14 @@ class PayNotifyLogic extends BaseLogic
//退款
$capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money);
}
if($check_user_sing){
self::descUserSing($order);
}
return true;
}
//积分
if($check_user_sing){
self::descUserSing($order);
}
//微信日志 user_order_refund
$capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1);
@ -308,9 +475,38 @@ 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 ) {
$user_number = bcmul($order['refund_price'], '0.10', 2);
$sing = [
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '退款扣除兑换券',
'financial_pm' => 0,
'store_id' => $order['store_id'],
'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();
}
}
}
return true;
}
/**
* 财务退还金额相关
* @param $orderSn
@ -357,7 +553,6 @@ class PayNotifyLogic extends BaseLogic
//日志记录
$model = new StoreCashFinanceFlow();
$model->store_id = $order['store_id'] ?? 0;
$model->store_id = $order['store_id'] ?? 0;
$model->cash_price = $order->pay_price;
$model->receivable = $order->pay_price;
$model->remark = '退款';
@ -399,6 +594,7 @@ class PayNotifyLogic extends BaseLogic
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '购买商品获得兑换券',
'financial_pm' => 1,
'store_id' => $order['store_id'],
'number' => $user_number,
];
@ -407,6 +603,27 @@ class PayNotifyLogic extends BaseLogic
return true;
}
public static function dealRechargeFrozen($order)
{
$total_vip = bcmul($order['price'],0.1,2);
$user_sing = new UserSign();
$sing = [
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '充值获得冻结兑换券',
'financial_pm' => 1,
'store_id' => $order['store_id'],
'type' => 1,
'status' => 1,
'number' => $total_vip,
'back_num' => $total_vip,
];
$user_sing->save($sing);
User::where('id',$order->uid)->inc('integral',$total_vip)->update();
return true;
}
/**
* 充值
@ -438,15 +655,20 @@ class PayNotifyLogic extends BaseLogic
bcscale(2);
// $user->now_money = bcadd($user->now_money, $price, 2);//v.1
//更新等级
if ($price >= Config::where('name','recharge')->value('value')) {
$user->user_ship = 1; //v.1
}
$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'];
}
$check = UserSign::where(['uid'=>$order->uid,'type'=>1])->count();
if(empty($check)){
self::dealRechargeFrozen($order);
}
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'])) {
@ -542,13 +764,14 @@ class PayNotifyLogic extends BaseLogic
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付
$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']);
if ($order['uid'] > 0 && $order['total_price'] > 500 && $order['pay_type'] !=18
&& $order['pay_type'] !=3) {
$financeLogic->save();
if ($order['uid'] > 0 && $order['total_price'] >= 500 ) {
$user_number = bcmul($order['pay_price'], '0.10', 2);
$sing = [
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '购买商品获得兑换券',
'financial_pm' => 1,
'store_id' => $order['store_id'],
'number' => $user_number,
];
@ -577,13 +800,13 @@ class PayNotifyLogic extends BaseLogic
$order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2);
self::dealVipAmount($order, $order['pay_type']);
}
if($order['total_price'] > 500 && $order['pay_type'] !=18
&& $order['pay_type'] !=3){
if($order['total_price'] >= 500 ){
$user_number = bcmul($order['pay_price'], '0.10', 2);
$sing = [
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '购买商品获得兑换券',
'financial_pm' => 1,
'store_id' => $order['store_id'],
'number' => $user_number,
'status' => 0,
@ -617,46 +840,35 @@ class PayNotifyLogic extends BaseLogic
if ($deposit > 0) {
if ($deposit > $store_profit) {
if ($store_profit > 0) {
SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $store_profit)->update();
// 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();
// 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();
// 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']); //平台手续费
}
}
} else {
if ($store_profit > 0) {
SystemStore::where('id', $order['store_id'])->inc('store_money', $store_profit)->update();
// 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']); //平台手续费
}
}
// if ($order['is_vip'] >= 1) {
if ($order['spread_uid'] > 0) {
$financeLogic->other_arr['vip_uid'] = $order['spread_uid'];
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);
if ($fees > 0) {
User::where('id', $order['spread_uid'])->inc('now_money', $fees)->update();
//记录用户余额收入
$GiveUser = User::where('id', $order['spread_uid'])->find();
$capitalFlowDao = new CapitalFlowLogic($GiveUser);
$capitalFlowDao->userIncome('system_balance_add', 'order', $order['id'], $fees);
$financeLogic->in($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //vip订单获得
$financeLogic->out($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
}
}
$fees = bcdiv(bcmul($order['pay_price'], '0.01', 2), 1, 2);
$count_frees = bcadd($count_frees, bcmul($fees, 3, 2), 2);
@ -670,7 +882,7 @@ class PayNotifyLogic extends BaseLogic
if ($arr1) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id');
if ($uid) {
User::where('id', $uid)->inc('integral', $fees)->update();
// User::where('id', $uid)->inc('integral', $fees)->update();
$village_uid = $uid;
}
}
@ -678,7 +890,7 @@ class PayNotifyLogic extends BaseLogic
if ($arr2) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id');
if ($uid) {
User::where('id', $uid)->inc('integral', $fees)->update();
// User::where('id', $uid)->inc('integral', $fees)->update();
$brigade_uid = $uid;
}
}
@ -725,14 +937,14 @@ class PayNotifyLogic extends BaseLogic
// 'user_ship' => 3,
// ];
if ($village_uid > 0) {
SystemStore::where('id', $village_uid)->inc('store_money', $fees)->update();
// 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();
// 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']);

View File

@ -5,6 +5,8 @@ namespace app\common\logic;
use app\common\enum\OrderEnum;
use app\common\enum\PayEnum;
use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
class StoreFinanceFlowLogic extends BaseLogic
{
@ -126,4 +128,28 @@ class StoreFinanceFlowLogic extends BaseLogic
$model->save();
}
/**
* 核销后更新用户余额
*/
public function updateStatusUser($id,$uid,$money,$order_id){
StoreFinanceFlow::where('id', $id)->update(['status' => 1]);
$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();
}
/**
* 核销后更新门店余额
*/
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){
SystemStore::where('id', $store_id)->inc('store_money', $money)->update();
}
if($deposit){
SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update();
}
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace app\queue\redis;
use app\common\enum\PayEnum;
use app\common\logic\PayNotifyLogic;
use app\common\model\retail\Cashierclass;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\system_store\SystemStore;
use app\common\model\user_recharge\UserRecharge;
use app\common\service\Curl;
use app\common\service\pay\PayService;
use app\common\service\PushService;
use Webman\RedisQueue\Consumer;
use support\exception\BusinessException;
use support\Log;
/**
* 企业微信订单推送队列消费
*/
class OrderWetchaPushSend implements Consumer
{
// 要消费的队列名
public $queue = 'order_wetcha_push_send';
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
public $connection = 'default';
// 消费
public function consume($data)
{
$url = getenv('WETCHA_PUSH');
if ($url) {
$order=$data['order'];
$order_id = $order['order_id'];
$total_price = $order['total_price'];
$pay_price = $order['pay_price'];
$pay_time = date('Y-m-d H:i:s', $order['pay_time']);
$phone = $order['user_phone'];
$pay_type = PayEnum::getPaySceneDesc($order['pay_type']);
$store_name = SystemStore::where('id', $order['store_id'])->value('name');
$cart_info=StoreOrderCartInfo::where('oid',$order['id'])->field('cart_info')->select();
$product_info="\r\n>商品信息:<font color=\"comment\">------------------</font>";
foreach($cart_info as $k=>$v['cart_info']){
$a=$v['cart_info']['cart_info']['name'].' 数量:'.$v['cart_info']['cart_info']['cart_num'].' 价格:'.$v['cart_info']['cart_info']['pay_price'].'元';
$product_info.="\r\n><font color=\"comment\">$a</font>";
}
$arr = ["msgtype" => "markdown", "markdown" => ["content" => "有新的订单请及时跟踪
>订单号:<font color=\"comment\">$order_id</font>
>门店信息:<font color=\"comment\">$store_name</font>"
.$product_info
."\r\n>下单时间:<font color=\"comment\">$pay_time</font>
>订单金额:<font color=\"comment\">$total_price</font>
>支付金额:<font color=\"comment\">$pay_price</font>
>支付方式:<font color=\"comment\">$pay_type</font>
>下单用户手机号:<font color=\"comment\">$phone</font>"]];
(new Curl())->postJson($url, json_encode($arr));
}
}
// 消费失败时
public function onConsumeFailure(\Throwable $exception, $package)
{
$package['max_attempts'] = 0;
Log::error('推送订单失败', ['order_id' => $package['data'], 'error' => $package['error']]);
return true;
}
}

View File

@ -46,6 +46,7 @@ class StoreStorageSend implements Consumer
$attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty();
Db::startTrans();
try {
$dealCate = self::dealChangeCate($find['cate_id']);
$product = [
'product_id' => $find['id'],
'image' => $find['image'],
@ -54,6 +55,8 @@ class StoreStorageSend implements Consumer
'keyword' => $find['keyword'],
'bar_code' => $find['bar_code'],
'cate_id' => $find['cate_id'],
'top_cate_id' => $dealCate['top_cate_id'],
'two_cate_id' => $dealCate['two_cate_id'],
'price' => $find['price'],
// 'cost' => $find['cost'], //v1.0
'cost' => $find['cost'],
@ -179,4 +182,31 @@ class StoreStorageSend implements Consumer
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
return $package;
}
/*
* 传入三级或者二级分类返还上级分类 一级那全是相同
*/
public static function dealChangeCate($cate_id)
{
$value =[];
$last_cate = Db::name('store_category')->where('id',$cate_id)->value('pid');
if(!empty($last_cate)){
//2
$value['two_cate_id'] = $last_cate;
//1
$first_cate = Db::name('store_category')->where('id',$value['two_cate_id'])->value('pid');
if(empty($first_cate)){//顶级了
$value['two_cate_id'] = $cate_id;
$value['top_cate_id'] = $last_cate;
}else{
$value['top_cate_id'] = $first_cate;
}
}else{
//1-2 选的1级目录
$value['two_cate_id'] = $cate_id;
$value['top_cate_id'] = $cate_id;
}
return $value;
}
}

View File

@ -67,6 +67,18 @@ class OrderLogic extends BaseLogic
return bcadd($todayAmount, $pay_price, 2);
}
public static function dealFlexiblePrice($where,$start,$end)
{
$todayAmount = UserRecharge::where($where)
->whereBetweenTime('create_time', $start, $end)
->sum('price');
$pay_price = StoreOrder::where($where)
->whereBetweenTime('create_time', $start, $end)
->sum('pay_price');
return bcadd($todayAmount, $pay_price, 2);
}
public static function sales($where,$time){
$select=StoreOrder::where($where)->whereDay('create_time',$time)->limit(10)->order('id desc')->field('id,order_id,pay_price,create_time')->select();
return $select?->toArray();

View File

@ -174,6 +174,13 @@ class StoreOrderController extends BaseAdminController
$order = OrderLogic::createOrder($cartId, $addressId, $user, $params);
if ($order != false) {
switch ($pay_type) {
case PayEnum::BALANCE_PAY:
//余额支付
PayNotifyLogic::handle('balancePay', $order['order_id'],[
'store_id' => $this->request->adminInfo['store_id'],
'staff_id' => $this->request->adminInfo['admin_id']
]);
return $this->success('余额支付成功');
case PayEnum::PURCHASE_FUNDS:
//采购款支付
PayNotifyLogic::handle('purchase_funds', $order['order_id'], [
@ -248,9 +255,17 @@ class StoreOrderController extends BaseAdminController
return $this->fail('订单不存在或已支付');
}
switch ($pay_type) {
case PayEnum::BALANCE_PAY:
//余额支付
PayNotifyLogic::handle('balancePay', $order['order_id'],[
'store_id' => $this->request->adminInfo['store_id'],
'staff_id' => $this->request->adminInfo['admin_id']
]);
return $this->success('余额支付成功');
case PayEnum::PURCHASE_FUNDS:
//采购款支付
PayNotifyLogic::handle('purchase_funds', $order['order_id'], ['uid' => $order['uid']]);
PayNotifyLogic::handle('purchase_funds', $order['order_id'], ['uid' => $order['uid'],'store_id' => $this->request->adminInfo['store_id'],
'staff_id' => $this->request->adminInfo['admin_id']]);
return $this->success('采购款支付成功', ['id' => $order['id']]);
case PayEnum::CASH_PAY:
//现金支付
@ -343,12 +358,6 @@ class StoreOrderController extends BaseAdminController
*/
public function rechange_amount()
{
// $order = UserRecharge::where('order_id','CZ1719052252643357')->find();
// $order['pay_price'] = $order['price'];
// d(1);
// PayNotifyLogic::handle('recharge', $order['order_id'], $order);
// d(1);
$pay_type = $this->request->post('pay_type');
$auth_code = $this->request->post('auth_code'); //微信支付条码
if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) {
@ -362,6 +371,7 @@ class StoreOrderController extends BaseAdminController
'order_id' => getNewOrderId('CZ'),
'price' => $params['price'],
'recharge_type' => 'INDUSTRYMEMBERS',
'user_ship'=>$params['user_ship']??0,
];
$order = UserRecharge::create($data);
$order['pay_price'] = $order['price'];

View File

@ -84,7 +84,8 @@ class WorkbenchLogic extends BaseLogic
$data['income_amount'] = StoreFinanceFlow::where($storeFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number');
//门店收款金额
$all_where['paid'] = 1;
$data['receipt_amount'] = OrderLogic::dayPayPrice($all_where,date('Y-m-d',time()));
// $data['receipt_amount'] = OrderLogic::dayPayPrice($all_where,date('Y-m-d',time()));
$data['receipt_amount'] = OrderLogic::dealFlexiblePrice($all_where,$startTime,$endTime);
// $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');

View File

@ -23,6 +23,8 @@ return [
app\admin\middleware\LoginMiddleware::class,
// 权限认证
app\admin\middleware\AuthMiddleware::class,
// 操作日志记录
app\admin\middleware\OperationLogMiddleware::class,
],
'api' => [
// 跨域中间件