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

Reviewed-on: #16
This commit is contained in:
mkm 2024-06-26 18:56:35 +08:00
commit af23ac1b44
52 changed files with 1457 additions and 445 deletions

View File

@ -14,6 +14,7 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\admin\lists\config\ConfigLists;
use app\admin\logic\auth\AuthLogic; use app\admin\logic\auth\AuthLogic;
use app\admin\logic\ConfigLogic; use app\admin\logic\ConfigLogic;
use think\facade\Db; use think\facade\Db;

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\config;
use app\admin\controller\BaseAdminController;
use app\admin\lists\config\ConfigLists;
use app\admin\logic\ConfigLogic;
use app\admin\validate\config\ConfigValidate;
/**
* 配置表控制器
* Class ConfigController
* @package app\admin\controller\config
*/
class ConfigController extends BaseAdminController
{
/**
* @notes 获取配置表列表
* @return \think\response\Json
* @author admin
* @date 2024/06/24 17:52
*/
public function lists()
{
return $this->dataLists(new ConfigLists());
}
/**
* @notes 添加配置表
* @return \think\response\Json
* @author admin
* @date 2024/06/24 17:52
*/
public function add()
{
$params = (new ConfigValidate())->post()->goCheck('add');
$result = ConfigLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ConfigLogic::getError());
}
/**
* @notes 编辑配置表
* @return \think\response\Json
* @author admin
* @date 2024/06/24 17:52
*/
public function edit()
{
$params = (new ConfigValidate())->post()->goCheck('edit');
$result = ConfigLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ConfigLogic::getError());
}
/**
* @notes 删除配置表
* @return \think\response\Json
* @author admin
* @date 2024/06/24 17:52
*/
public function delete()
{
$params = (new ConfigValidate())->post()->goCheck('delete');
ConfigLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取配置表详情
* @return \think\response\Json
* @author admin
* @date 2024/06/24 17:52
*/
public function detail()
{
$params = (new ConfigValidate())->goCheck('detail');
$result = ConfigLogic::detail($params);
return $this->data($result);
}
}

View File

@ -122,12 +122,12 @@ class StoreOrderController extends BaseAdminController
$refund = (new \app\common\logic\store_order\StoreOrderLogic()) $refund = (new \app\common\logic\store_order\StoreOrderLogic())
->refund($params['order_id'],$money,$money); ->refund($params['order_id'],$money,$money);
if($refund){ if($refund){
$arr = [ // $arr = [
'amount'=>[ // 'amount'=>[
'refund'=>$money // 'refund'=>$money
] // ]
]; // ];
PayNotifyLogic::refund($params['order_id'],$arr); // PayNotifyLogic::refund($params['order_id'],$arr);
return $this->success(); return $this->success();
} }
} }
@ -148,7 +148,7 @@ class StoreOrderController extends BaseAdminController
PayNotifyLogic::cash_refund($params['order_id']); PayNotifyLogic::cash_refund($params['order_id']);
return $this->success(); return $this->success();
} }
//支付包支付 //todo 支付包支付
return $this->fail('退款失败'); return $this->fail('退款失败');
} }

View File

@ -7,6 +7,8 @@ use app\admin\controller\BaseAdminController;
use app\admin\lists\user_recharge\UserRechargeLists; use app\admin\lists\user_recharge\UserRechargeLists;
use app\admin\logic\user_recharge\UserRechargeLogic; use app\admin\logic\user_recharge\UserRechargeLogic;
use app\admin\validate\user_recharge\UserRechargeValidate; use app\admin\validate\user_recharge\UserRechargeValidate;
use app\common\logic\PayNotifyLogic;
use app\common\model\user\UserRecharge;
/** /**
@ -91,5 +93,33 @@ class UserRechargeController extends BaseAdminController
return $this->data($result); return $this->data($result);
} }
public function refund()
{
$params = (new UserRechargeValidate())->post()->goCheck('refund');
$detail = UserRecharge::where('id',$params['id'])->findOrEmpty();
if(empty($detail)){
return $this->fail('无该充值订单请检查');
}
//现金
if($detail['recharge_type'] =='CASH_PAY'){
PayNotifyLogic::recharge_cash_refund($params['id']);
return $this->success();
}
//微信
if($detail['recharge_type'] == 'INDUSTRYMEMBERS'){
$money = (int)bcmul($detail['price'],100);
(new \app\common\logic\store_order\StoreOrderLogic())
->refund($detail['order_id'],$money,$money);
return $this->success();
}
//支付宝
if($detail['recharge_type'] == 'ALI_INDUSTRYMEMBERS'){
}
return $this->success();
}
} }

View File

@ -0,0 +1,64 @@
<?php
namespace app\admin\lists\config;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\app_update\AppUpdate;
use app\common\lists\ListsSearchInterface;
use app\common\model\Config;
/**
* 配置列表
* Class ConfigLists
* @package app\admin\lists\config
*/
class ConfigLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/05/30 10:25
*/
public function setSearch(): array
{
return [
'=' => ['name', 'type'],
];
}
/**
* @notes 获取配置列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/05/30 10:25
*/
public function lists(): array
{
return Config::where($this->searchWhere)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取配置数量
* @return int
* @author likeadmin
* @date 2024/05/30 10:25
*/
public function count(): int
{
return AppUpdate::where($this->searchWhere)->count();
}
}

View File

@ -61,8 +61,8 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
//2或者1 //2或者1
$where[]=['cate_id','=',$class_all]; $where[]=['cate_id','=',$class_all];
} }
$this->searchWhere[]=$where;
return StoreBranchProduct::where($this->searchWhere)->where($where) return StoreBranchProduct::where($this->searchWhere)
->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost','purchase', 'status','batch','vip_price','manufacturer_information']) ->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost','purchase', 'status','batch','vip_price','manufacturer_information'])
->when(!empty($this->adminInfo['store_id']), function ($query) { ->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']); $query->where('store_id', $this->adminInfo['store_id']);
@ -99,17 +99,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
*/ */
public function count(): int public function count(): int
{ {
$status = $this->params['status'] ?? ''; return StoreBranchProduct::where($this->searchWhere)
$class_all=$this->request->get('class_all');
$where=[];
if($class_all){
$arr=Cate::where('pid',$class_all)->column('id');
if($arr){
$arr2=Cate::where('pid','in',$arr)->column('id');
$where[]=['cate_id','in',array_merge($arr,$arr2)];
}
}
return StoreBranchProduct::where($this->searchWhere)->where($where)
->when(!empty($this->adminInfo['store_id']), function ($query) { ->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']); $query->where('store_id', $this->adminInfo['store_id']);
}) })

View File

@ -81,57 +81,57 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt
$item['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']); $item['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']);
})->toArray(); })->toArray();
foreach ($data as $key => $item) { // foreach ($data as $key => $item) {
$list1 = StoreFinanceFlow::where('order_id', $item['order_id'])->where('financial_type', '>', 1)->field($field)->select()->each(function ($item) { // $list1 = StoreFinanceFlow::where('order_id', $item['order_id'])->where('financial_type', '>', 1)->field($field)->select()->each(function ($item) {
if ($item['user_id'] <= 0) { // if ($item['user_id'] <= 0) {
$item['nickname'] = '游客'; // $item['nickname'] = '游客';
} else { // } else {
$id = $item['user_id']; // $id = $item['user_id'];
$item['nickname'] = User::where('id', $item['user_id'])->value('nickname') . "|$id"; // $item['nickname'] = User::where('id', $item['user_id'])->value('nickname') . "|$id";
} // }
if (!empty($this->request->adminInfo['store_id'])) { // if (!empty($this->request->adminInfo['store_id'])) {
$item['financial_pm'] = $item['financial_pm'] == 0 ? 1 : 0; // $item['financial_pm'] = $item['financial_pm'] == 0 ? 1 : 0;
} // }
if ($item['financial_pm'] == 0) { // if ($item['financial_pm'] == 0) {
$item['number'] = '-' . $item['number']; // $item['number'] = '-' . $item['number'];
$item['financial_type_name'] = '订单支出:' . OrderEnum::getFinancialType($item['financial_type']); // $item['financial_type_name'] = '订单支出:' . OrderEnum::getFinancialType($item['financial_type']);
} else { // } else {
$item['financial_type_name'] = OrderEnum::getFinancialType($item['financial_type']) . '获得'; // $item['financial_type_name'] = OrderEnum::getFinancialType($item['financial_type']) . '获得';
$item['number'] = '+' . $item['number']; // $item['number'] = '+' . $item['number'];
} // }
$item['staff_name'] = SystemStoreStaff::where('id', $item['staff_id'])->value('staff_name'); // $item['staff_name'] = SystemStoreStaff::where('id', $item['staff_id'])->value('staff_name');
$item['store_name'] = $item['store_id'] > 0 ? SystemStore::where('id', $item['store_id'])->value('name') : ''; // $item['store_name'] = $item['store_id'] > 0 ? SystemStore::where('id', $item['store_id'])->value('name') : '';
$item['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']); // $item['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']);
}); // });
$list2 = UserSign::where('order_id', $item['order_sn'])->whereIn('user_ship', [0, 2, 3])->select(); // $list2 = UserSign::where('order_id', $item['order_sn'])->whereIn('user_ship', [0, 2, 3])->select();
foreach ($list2 as $k => $v) { // foreach ($list2 as $k => $v) {
$list2[$k]['id'] = 'JF' . $v['id']; // $list2[$k]['id'] = 'JF' . $v['id'];
$list2[$k]['order_sn'] = $item['order_sn']; // $list2[$k]['order_sn'] = $item['order_sn'];
$list2[$k]['store_name'] = $item['store_name']; // $list2[$k]['store_name'] = $item['store_name'];
if($v['user_ship']==0){ // if($v['user_ship']==0){
$list2[$k]['financial_pm'] = 1; // $list2[$k]['financial_pm'] = 1;
$list2[$k]['number'] = '+' . $v['number']; // $list2[$k]['number'] = '+' . $v['number'];
}else{ // }else{
if($v['financial_pm']==1){ // if($v['financial_pm']==1){
$list2[$k]['financial_pm'] = 1; // $list2[$k]['financial_pm'] = 1;
$list2[$k]['number'] = '+' . $v['number']; // $list2[$k]['number'] = '+' . $v['number'];
}else{ // }else{
$list2[$k]['financial_pm'] = 0; // $list2[$k]['financial_pm'] = 0;
$list2[$k]['number'] = '-' . $v['number']; // $list2[$k]['number'] = '-' . $v['number'];
} // }
} // }
$list2[$k]['nickname'] = $v['uid'] > 0 ? User::where('id', $v['uid'])->value('nickname') . '|' . $v['uid'] : '游客'; // $list2[$k]['nickname'] = $v['uid'] > 0 ? User::where('id', $v['uid'])->value('nickname') . '|' . $v['uid'] : '游客';
$list2[$k]['financial_type_name'] = $v['title']; // $list2[$k]['financial_type_name'] = $v['title'];
$list2[$k]['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']); // $list2[$k]['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']);
} // }
$list3 = array_merge($list1->toArray(), $list2->toArray()); // $list3 = array_merge($list1->toArray(), $list2->toArray());
// 提取 financial_pm 字段到单独的数组 // // 提取 financial_pm 字段到单独的数组
$financial_pm = array_column($list3, 'financial_pm'); // $financial_pm = array_column($list3, 'financial_pm');
// 对 financial_pm 数组进行排序,这将影响原始数组 // // 对 financial_pm 数组进行排序,这将影响原始数组
array_multisort($financial_pm, SORT_ASC, $list3); // array_multisort($financial_pm, SORT_ASC, $list3);
$data[$key]['list']=$list3; // $data[$key]['list']=$list3;
} // }
return $data; return $data;
} }

View File

@ -69,10 +69,10 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
} }
$product = StoreOrderCartInfo::where('oid', $item['id'])->field(['id', 'oid', 'product_id', 'cart_info']) $product = StoreOrderCartInfo::where('oid', $item['id'])->field(['id', 'oid', 'product_id', 'cart_info'])
->limit(3)->select(); ->limit(3)->select();
foreach ($product as &$items) { foreach ($product as &$items) {
$items['store_name'] = $items['cart_info']['name']; $items['store_name'] = $items['cart_info']['name'];
$items['image'] = $items['cart_info']['image']; $items['image'] = $items['cart_info']['image'];
} }
$item['product'] = $product; $item['product'] = $product;
return $item; return $item;
}) })

View File

@ -4,6 +4,7 @@ namespace app\admin\lists\store_product;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
use app\common\model\cate\Cate;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\store_category\StoreCategory; use app\common\model\store_category\StoreCategory;
@ -45,6 +46,17 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
*/ */
public function lists(): array 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];
}
}
return StoreProduct::where($this->searchWhere) 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', 'cate_id','batch', 'price','vip_price','sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase','bar_code','manufacturer_information'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)

View File

@ -44,7 +44,7 @@ class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterfa
public function lists(): array public function lists(): array
{ {
return UserRecharge::where($this->searchWhere) return UserRecharge::where($this->searchWhere)
->field(['id', 'uid', 'order_id', 'price', 'recharge_type', 'paid', 'pay_time']) ->field(['id', 'uid', 'order_id', 'price', 'recharge_type', 'paid', 'pay_time','status','refund_time'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) { ->select()->each(function ($item) {
@ -54,11 +54,19 @@ class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterfa
}else{ }else{
$item['pay_time']=''; $item['pay_time']='';
} }
if($item['refund_time']>0){
$item['refund_time']=date('Y-m-d H:i:s',$item['refund_time']);
}else{
$item['refund_time']='';
}
if($item['paid']==1){ if($item['paid']==1){
$item['paid_name']='已充值'; $item['paid_name']='已充值';
}else{ }else{
$item['paid_name']='未充值'; $item['paid_name']='未充值';
} }
if($item['status']== -1){
$item['paid_name']='已退款';
}
return $item; return $item;
}) })
->toArray(); ->toArray();

View File

@ -14,17 +14,97 @@
namespace app\admin\logic; namespace app\admin\logic;
use app\common\logic\BaseLogic;
use app\common\model\Config;
use app\common\model\dict\DictData; use app\common\model\dict\DictData;
use app\common\service\{FileService, ConfigService}; use app\common\service\{FileService, ConfigService};
use think\facade\Db;
/** /**
* 配置类逻辑层 * 配置类逻辑层
* Class ConfigLogic * Class ConfigLogic
* @package app\admin\logic * @package app\admin\logic
*/ */
class ConfigLogic class ConfigLogic extends BaseLogic
{ {
/**
* @notes 添加配置表
* @param array $params
* @return bool
* @author admin
* @date 2024/06/24 17:52
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Config::create([
'type' => $params['type'],
'name' => $params['name'],
'value' => $params['value']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑配置表
* @param array $params
* @return bool
* @author admin
* @date 2024/06/24 17:52
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Config::where('id', $params['id'])->update([
'type' => $params['type'],
'name' => $params['name'],
'value' => $params['value']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除配置表
* @param array $params
* @return bool
* @author admin
* @date 2024/06/24 17:52
*/
public static function delete(array $params): bool
{
return Config::destroy($params['id']);
}
/**
* @notes 获取配置表详情
* @param $params
* @return array
* @author admin
* @date 2024/06/24 17:52
*/
public static function detail($params): array
{
return Config::findOrEmpty($params['id'])->toArray();
}
/** /**
* @notes 获取配置 * @notes 获取配置
* @return array * @return array
@ -68,7 +148,7 @@ class ConfigLogic
if (!is_string($type)) { if (!is_string($type)) {
return []; return [];
} }
$type = explode(',', $type); $type = explode(',', $type);
$lists = DictData::whereIn('type_value', $type)->select()->toArray(); $lists = DictData::whereIn('type_value', $type)->select()->toArray();
@ -86,7 +166,4 @@ class ConfigLogic
} }
return $result; return $result;
} }
}
}

View File

@ -39,6 +39,7 @@ class StoreProductLogic extends BaseLogic
$data = [ $data = [
'store_name' => $params['store_name'], 'store_name' => $params['store_name'],
'image' => $params['image'], 'image' => $params['image'],
'store_info' => $params['store_info'] ?? '',
'bar_code' => $params['bar_code'] ?? '', 'bar_code' => $params['bar_code'] ?? '',
'cate_id' => $params['cate_id'], 'cate_id' => $params['cate_id'],
'unit' => $params['unit'], 'unit' => $params['unit'],
@ -52,6 +53,7 @@ class StoreProductLogic extends BaseLogic
'manufacturer_information' => $params['manufacturer_information']??'', 'manufacturer_information' => $params['manufacturer_information']??'',
'swap' => $params['swap'] ?? 0, 'swap' => $params['swap'] ?? 0,
'batch' => $params['batch'] ?? 0, 'batch' => $params['batch'] ?? 0,
'product_type' => $params['product_type'] ?? 0,
]; ];
// if ($params['rose'] > 0) { // if ($params['rose'] > 0) {
// $rose_price = bcmul($params['cost'], $params['rose'], 2); // $rose_price = bcmul($params['cost'], $params['rose'], 2);
@ -140,6 +142,7 @@ class StoreProductLogic extends BaseLogic
'store_name' => $params['store_name'], 'store_name' => $params['store_name'],
'image' => $params['image'], 'image' => $params['image'],
'bar_code' => $params['bar_code'] ?? '', 'bar_code' => $params['bar_code'] ?? '',
'store_info' => $params['store_info'] ?? '',
'cate_id' => $params['cate_id'], 'cate_id' => $params['cate_id'],
'unit' => $params['unit'], 'unit' => $params['unit'],
'stock' => $params['stock'], 'stock' => $params['stock'],
@ -152,7 +155,6 @@ class StoreProductLogic extends BaseLogic
'batch' => $params['batch'], 'batch' => $params['batch'],
'manufacturer_information' => $params['manufacturer_information']??'', 'manufacturer_information' => $params['manufacturer_information']??'',
'swap' => $params['swap'] ?? 0, 'swap' => $params['swap'] ?? 0,
]; ];
StoreProduct::where('id', $params['id'])->update($data); StoreProduct::where('id', $params['id'])->update($data);
@ -181,6 +183,7 @@ class StoreProductLogic extends BaseLogic
'cost' => $params['cost'],'unit'=>$params['unit'], 'cost' => $params['cost'],'unit'=>$params['unit'],
'batch'=>$params['batch'],'store_name'=>$params['store_name'], 'batch'=>$params['batch'],'store_name'=>$params['store_name'],
'manufacturer_information' => $params['manufacturer_information']??'', 'manufacturer_information' => $params['manufacturer_information']??'',
'store_info' => $params['store_info']??'',
]); ]);
Db::commit(); Db::commit();

View File

@ -80,7 +80,6 @@ class UserLogic extends BaseLogic
$password = create_password(123456, $passwordSalt); $password = create_password(123456, $passwordSalt);
$defaultAvatar = config('project.default_image.admin_avatar'); $defaultAvatar = config('project.default_image.admin_avatar');
$avatar = !empty($params['avatar']) ? FileService::setFileUrl($params['avatar']) : $defaultAvatar; $avatar = !empty($params['avatar']) ? FileService::setFileUrl($params['avatar']) : $defaultAvatar;
Db::startTrans(); Db::startTrans();
try { try {
$data=[ $data=[
@ -104,13 +103,13 @@ class UserLogic extends BaseLogic
UserAddress::create([ UserAddress::create([
'uid' => $res['id'], 'uid' => $res['id'],
'real_name' => $params['real_name']??"", 'real_name' => $params['real_name']??"",
'mobile' => $params['mobile'], 'mobile' => $params['mobile']??'',
'province' => $params['province'], 'province' => $params['province']??'',
'city' => $params['city'], 'city' => $params['city']??'',
'area' => $params['area'], 'area' => $params['area']??'',
'street' => $params['street'], 'street' => $params['street']??'',
'village' => $params['village'], 'village' => $params['village']??'',
'brigade' => $params['brigade'], 'brigade' => $params['brigade']??'',
'is_default' => 1, 'is_default' => 1,
]); ]);
Db::commit(); Db::commit();

View File

@ -0,0 +1,86 @@
<?php
namespace app\admin\validate\config;
use app\common\validate\BaseValidate;
/**
* 配置表验证器
* Class ConfigValidate
* @package app\admin\validate\config
*/
class ConfigValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'name' => 'require',
'value' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'name' => '名称',
'value' => '值',
];
/**
* @notes 添加场景
* @return ConfigValidate
* @author admin
* @date 2024/06/24 17:52
*/
public function sceneAdd()
{
return $this->only(['name','value']);
}
/**
* @notes 编辑场景
* @return ConfigValidate
* @author admin
* @date 2024/06/24 17:52
*/
public function sceneEdit()
{
return $this->only(['id','name','value']);
}
/**
* @notes 删除场景
* @return ConfigValidate
* @author admin
* @date 2024/06/24 17:52
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ConfigValidate
* @author admin
* @date 2024/06/24 17:52
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -35,6 +35,7 @@ class UserValidate extends BaseValidate
'brigade' => 'require', 'brigade' => 'require',
'user_ship' => 'require', 'user_ship' => 'require',
'type' => 'require|number', 'type' => 'require|number',
'code' => 'require|number',
]; ];
@ -59,8 +60,8 @@ class UserValidate extends BaseValidate
'brigade' => ' 队', 'brigade' => ' 队',
'user_ship' => ' 会员类型', 'user_ship' => ' 会员类型',
'type' => '查询类型', 'type' => '查询类型',
'code' => '验证码',
]; ];
public function sceneFund() public function sceneFund()
{ {
return $this->only(['type','id']); return $this->only(['type','id']);

View File

@ -32,6 +32,12 @@ class UserRechargeValidate extends BaseValidate
]; ];
public function sceneRefund()
{
return $this->only(['id']);
}
/** /**
* @notes 添加场景 * @notes 添加场景
* @return UserRechargeValidate * @return UserRechargeValidate

View File

@ -10,8 +10,12 @@ use app\common\model\Config as ModelConfig;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\service\pay\PayService; use app\common\service\pay\PayService;
use app\common\service\PushService;
use app\common\service\wechat\WechatTemplate; use app\common\service\wechat\WechatTemplate;
use app\statistics\logic\OrderLogic;
use Exception; use Exception;
use Overtrue\EasySms\EasySms;
use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;
use support\Cache; use support\Cache;
use think\facade\Db; use think\facade\Db;
use Webman\Config; use Webman\Config;
@ -28,18 +32,60 @@ class IndexController extends BaseApiController
public function index() public function index()
{ {
$order = [ $config = [
'out_trade_no' => 'CZ1719197818549414', // 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' => '里海科技',
],
//...
],
]; ];
$app = new PayService(0);
try { try {
$res = $app->wechat->query($order); $easySms = new EasySms($config);
} catch (\Exception $e) { $template = getenv('SMS_TEMPLATE');
return $this->fail($e->extra['message']); $a = $easySms->send(18715753257, [
'content' => '您的验证码为: 6379',
'template' => $template,
'data' => [
'code' => 6379
],
]);
// d($a);
}catch (NoGatewayAvailableException $exception){
throw new \Exception($exception->getExceptions());
} }
d($res);
d($a,getenv('SMS_TEMPLATE'));
$all_where['paid'] = 1;
d(OrderLogic::dayPayPrice($all_where,date('Y-m-d',time())));
$uid=9;
$a= PushService::push('wechat_mmp_'.$uid, $uid, ['type'=>'INDUSTRYMEMBERS','msg'=>'支付超时,订单已被取消,请重新提交订单','data'=>['id'=>5]]);
return json($a);

View File

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

View File

@ -12,9 +12,11 @@ use app\api\validate\UserValidate;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
use app\common\logic\PaymentLogic; use app\common\logic\PaymentLogic;
use app\common\logic\PayNotifyLogic; use app\common\logic\PayNotifyLogic;
use app\common\model\Config;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\user_create_log\UserCreateLog; use app\common\model\user_create_log\UserCreateLog;
use app\common\model\user_recharge\UserRecharge; use app\common\model\user_recharge\UserRecharge;
use support\Cache;
use Webman\RedisQueue\Redis; use Webman\RedisQueue\Redis;
class StoreController extends BaseApiController class StoreController extends BaseApiController
@ -47,10 +49,9 @@ class StoreController extends BaseApiController
if($store_id){ if($store_id){
$where['id'] = $store_id; $where['id'] = $store_id;
} }
$info = StoreLogic::search($where); $info = StoreLogic::search($where);
if ($info) { if ($info) {
return $this->success('ok',$info??[]); return $this->success('ok',$info);
} else { } else {
return $this->fail('店铺不存在'); return $this->fail('店铺不存在');
} }
@ -64,6 +65,18 @@ class StoreController extends BaseApiController
$params = (new UserValidate())->post()->goCheck('rechargeStoreMoney'); $params = (new UserValidate())->post()->goCheck('rechargeStoreMoney');
$auth_code = $this->request->post('auth_code'); //微信支付条码 $auth_code = $this->request->post('auth_code'); //微信支付条码
$recharge_type = $this->request->post('recharge_type',''); //微信支付条码 $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('验证码错误');
}
}
$find=User::where('mobile',$params['mobile'])->find(); $find=User::where('mobile',$params['mobile'])->find();
if(!$find){ if(!$find){
$params['create_uid']=$this->userId; $params['create_uid']=$this->userId;
@ -72,15 +85,19 @@ class StoreController extends BaseApiController
$find['real_name']=$params['real_name']; $find['real_name']=$params['real_name'];
$find->save(); $find->save();
} }
if($find === false){
return $this->fail(UserUserLogic::getError());
}
if($recharge_type!='INDUSTRYMEMBERS'){ if($recharge_type!='INDUSTRYMEMBERS'){
return $this->success('添加用户成功'); return $this->success('添加用户成功');
} }
$data=[ $data=[
'store_id'=>$params['store_id'], 'store_id'=>$params['store_id'],
'uid'=>$find['id'], 'uid'=>$find['id'],
'other_uid'=>$this->userId,
'staff_id'=>0, 'staff_id'=>0,
'order_id'=>getNewOrderId('CZ'), 'order_id'=>getNewOrderId('CZ'),
'price'=>1000, 'price'=>Config::where('name','recharge')->value('value')??1000,
'recharge_type'=>'INDUSTRYMEMBERS', 'recharge_type'=>'INDUSTRYMEMBERS',
]; ];
$order = UserRecharge::create($data); $order = UserRecharge::create($data);
@ -99,6 +116,35 @@ class StoreController extends BaseApiController
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]); return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
} }
/**
* 重新充值会员
*/
public function again_recharge()
{
$auth_code = $this->request->post('auth_code'); //微信支付条码
$id = $this->request->post('id',0); //id
$order = UserRecharge::where('id', $id)->where('paid',0)->find();
if(!$order){
return $this->fail('订单不存在');
}
$order_id=getNewOrderId('CZ');
UserRecharge::where('id', $id)->update(['order_id'=>$order_id]);
$order['order_id']=$order_id;
$order['pay_price']=$order['price'];
$result = PaymentLogic::codepay($auth_code, $order,'条码支付');
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError());
}
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result);
} else {
Redis::send('send-code-pay', ['order_id' => $order['order_id'],'pay_type'=>'recharge']);
return $this->success('用户支付中');
}
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
}
/** /**
* 门店会员充值数量 * 门店会员充值数量
*/ */

View File

@ -4,9 +4,12 @@ namespace app\api\controller\user;
use app\api\controller\BaseApiController; use app\api\controller\BaseApiController;
use app\api\logic\user\UserLogic; use app\api\logic\user\UserLogic;
use app\api\service\UserTokenService;
use app\api\validate\UserValidate; use app\api\validate\UserValidate;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
use app\common\logic\PaymentLogic; use app\common\logic\PaymentLogic;
use app\common\model\user\User;
use app\common\model\user_sign\UserSign;
use support\Cache; use support\Cache;
use think\Exception; use think\Exception;
@ -36,7 +39,14 @@ class UserController extends BaseApiController
if ($result === false) { if ($result === false) {
return $this->fail(UserLogic::getError()); return $this->fail(UserLogic::getError());
} }
$data = UserLogic::info($this->userId); if($result && is_numeric($result)){
$data = UserLogic::info($result);
$userInfo = UserTokenService::setToken($result, 1);
$data['token'] = $userInfo['token'];
}else{
$data = UserLogic::info($this->userId);
}
return $this->success('绑定成功', $data, 1, 1); return $this->success('绑定成功', $data, 1, 1);
} }
@ -145,6 +155,7 @@ class UserController extends BaseApiController
return $this->fail('发送失败'); return $this->fail('发送失败');
} }
//登录
public function login_sms() public function login_sms()
{ {
$params = (new UserValidate())->post()->goCheck('login'); $params = (new UserValidate())->post()->goCheck('login');
@ -155,6 +166,18 @@ class UserController extends BaseApiController
return $this->fail('发送失败'); return $this->fail('发送失败');
} }
//报备
public function reporting_sms()
{
$params = (new UserValidate())->post()->goCheck('login');
$res = (new UserLogic())->dealReportingSms($params['account']);
if ($res){
return $this->success('发送成功',[],1,1);
}
return $this->fail('发送失败');
}
@ -164,7 +187,7 @@ class UserController extends BaseApiController
$remark = $this->userId.'_payPassword'; $remark = $this->userId.'_payPassword';
$code = Cache::get($remark); $code = Cache::get($remark);
if ($code && isset($params['code']) && $code !== $params['code']) { if ($code && isset($params['code']) && $code !== $params['code']) {
throw new Exception('验证码错误'); return $this->fail('验证码错误');
} }
if ($params['rePassword'] !== $params['password']) if ($params['rePassword'] !== $params['password'])
return $this->fail('两次密码不一致'); return $this->fail('两次密码不一致');
@ -207,8 +230,16 @@ class UserController extends BaseApiController
$params['page_no'] = $page_no > 0 ? $page_no : 1; $params['page_no'] = $page_no > 0 ? $page_no : 1;
$params['page_size'] = $page_size > 0 ? $page_size : 15; $params['page_size'] = $page_size > 0 ? $page_size : 15;
$res = UserLogic::dealDetails($params,$this->userId); $res = UserLogic::dealDetails($params,$this->userId);
$integral = User::where('id',$this->userId)->value('integral');
$number = UserSign::where('id',$this->userId)->where('status',0)->sum('number');
$GetNumber = UserSign::where('id',$this->userId)->where('status',1)->sum('number');
$res['page_no'] = $params['page_no']; $res['page_no'] = $params['page_no'];
$res['page_size'] = $params['page_size']; $res['page_size'] = $params['page_size'];
$res['extend'] = [
'integral'=>$integral,
'number'=>$number,
'get_number'=>$GetNumber
];
return $this->success('ok', $res); return $this->success('ok', $res);
} }

View File

@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\order\Cart; use app\common\model\order\Cart;
use app\common\lists\ListsExtendInterface; use app\common\lists\ListsExtendInterface;
use app\common\model\Config;
use app\common\model\dict\DictType; use app\common\model\dict\DictType;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_attr_value\StoreProductAttrValue;
@ -23,6 +24,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
protected $total_price = 0; protected $total_price = 0;
protected $activity_price = 0; protected $activity_price = 0;
protected $off_activity = 0;
/** /**
@ -60,31 +62,23 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
return $item; return $item;
}) })
->toArray(); ->toArray();
// $check = DictType::where('type', 'activities')->find(); $off_activity = Config::where('name', 'off_activity')->value('value');
$user = User::where('id', $userId)->find(); $this->off_activity=$off_activity;
foreach ($list as $key => &$item) { foreach ($list as $key => &$item) {
$find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']])
$find = StoreBranchProduct::where(['product_id' => $item['product_id'],'store_id' => $item['store_id']]) ->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price')
->field('product_id,image,cost price,cost,store_name,unit,delete_time,vip_price')
->withTrashed() ->withTrashed()
->find(); ->find();
if ($find) { if ($find) {
// if ($user && $user['user_ship'] == 1) { if($off_activity==1){
// //更新 会员为1的时候原价减去会员价 $this->activity_price = bcadd(bcmul($find['cost'],$item['cart_num'], 2), $this->activity_price, 2);
// $deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$item['cart_num'],2); }
// $this->activity_price = bcadd($this->activity_price, $deduction_price_count, 2);
// }elseif ($user && $user['user_ship'] == 4) {
// //更新 为4商户的时候减去商户价格
// $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$item['cart_num'],2);
// $this->activity_price = bcadd( $this->activity_price, $deduction_price_count, 2);
// }else{
// $this->activity_price =0;
// }
$item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2);
$this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2);
$item['imgs'] = $find['image']; $item['imgs'] = $find['image'];
$item['sell'] = $find['price']; $item['price'] = $find['price'];
$item['cost'] = $find['cost'];
$item['goods_name'] = $find['store_name']; $item['goods_name'] = $find['store_name'];
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
} }
@ -111,10 +105,19 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
public function extend() public function extend()
{ {
return [ $data= [
'off_activity' => $this->off_activity,
'total_price' => $this->total_price, 'total_price' => $this->total_price,
'activity_price' => $this->activity_price, 'msg' => '',
'pay_price'=> bcsub($this->total_price, $this->activity_price, 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['pay_price']= $this->activity_price;
}
}
return $data;
} }
} }

View File

@ -46,18 +46,20 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
{ {
$userId = $this->request->userId; $userId = $this->request->userId;
if (!$userId) return []; if (!$userId) return [];
$data = StoreOrder::with(['store'])->where($this->searchWhere)->where('uid', $userId) $data = StoreOrder::with(['store'])->where($this->searchWhere)->where(['uid'=>$userId])
->whereIn('shipping_type',[1,2])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()
->each(function ($item) { ->each(function ($item) {
$item['goods_list'] = StoreOrderCartInfo::where('oid', $item['id']) $item['goods_list'] = StoreOrderCartInfo::where('oid', $item['id'])
->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time,old_cart_id')->limit(3)->select() ->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time,old_cart_id,cart_info')->limit(3)->select()
->each(function ($v) use ($item) { ->each(function ($v) use ($item) {
$find = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $item['store_id'])->withTrashed()->find(); $find = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $item['store_id'])->withTrashed()->find();
$v['store_name'] = $find['store_name']; $v['store_name'] = $find['store_name'];
$v['image'] = $find['image']; $v['image'] = $find['image'];
$v['price'] = $find['price']; // $v['price'] = $find['price'];
$v['price'] = $v['cart_info']['price'];
$v['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? ''; $v['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? '';
}); });
$item['goods_count'] = count(explode(',', $item['cart_id'])); $item['goods_count'] = count(explode(',', $item['cart_id']));
@ -85,6 +87,6 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
public function count(): int public function count(): int
{ {
$userId = $this->request->userId; $userId = $this->request->userId;
return StoreOrder::where($this->searchWhere)->where('uid', $userId)->count(); return StoreOrder::where($this->searchWhere)->whereIn('shipping_type',[1,2])->where('uid', $userId)->count();
} }
} }

View File

@ -4,12 +4,14 @@ namespace app\api\lists\product;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsExtendInterface;
use app\common\lists\ListsSortInterface; use app\common\lists\ListsSortInterface;
use app\common\model\dict\DictType; use app\common\model\dict\DictType;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\cate\Cate; use app\common\model\cate\Cate;
use app\common\model\Config;
//use app\common\model\goods\GoodsLabel; //use app\common\model\goods\GoodsLabel;
use think\facade\Db; use think\facade\Db;
@ -18,7 +20,7 @@ use think\facade\Db;
* Class goods * Class goods
* @package app\api\goods * @package app\api\goods
*/ */
class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface, ListsExtendInterface
{ {
@ -34,6 +36,10 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
'=' => ['store_id', 'cate_id'], '=' => ['store_id', 'cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'], '%pipe_like%' => ['store_name' => 'store_name|bar_code'],
]; ];
return [
'=' => ['store_id', 'cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
];
} }
/** /**
* @notes 设置支持排序字段 * @notes 设置支持排序字段
@ -54,7 +60,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
*/ */
public function setDefaultOrder(): array public function setDefaultOrder(): array
{ {
return [ 'price' => 'asc','id' => 'desc']; return ['price' => 'asc', 'id' => 'desc'];
} }
/** /**
@ -75,21 +81,28 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
if ($arr) { if ($arr) {
$arr2 = Cate::where('pid', 'in', $arr)->column('id'); $arr2 = Cate::where('pid', 'in', $arr)->column('id');
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
}else{ } else {
$this->searchWhere[] = ['cate_id','=',$class_all]; $this->searchWhere[] = ['cate_id', '=', $class_all];
} }
} }
$order = $this->request->get('order','');
$field = $this->request->get('field','');
if(empty($order)||empty($field)){
$order = $this->sortOrder;
}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';
$this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[] = ['stock', '>', 0]; $this->searchWhere[] = ['stock', '>', 0];
return StoreBranchProduct::where($this->searchWhere) return StoreBranchProduct::where($this->searchWhere)
->field(['id', 'product_id', 'cate_id', 'store_name', 'cost', 'store_id','vip_price','purchase', 'cost price', 'bar_code', 'image', 'sales', 'store_info', 'delete_time', 'unit', 'batch']) ->field($fields)
->with(['className', 'unitName']) ->with(['className', 'unitName'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order($this->sortOrder) ->order($order)
// ->page($this->limitOffset +1,$this->limitLength) // ->page($this->limitOffset +1,$this->limitLength)
->select()->toArray(); ->select()->toArray();
} }
@ -104,4 +117,22 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
return StoreBranchProduct::where($this->searchWhere) return StoreBranchProduct::where($this->searchWhere)
->count(); ->count();
} }
public function extend()
{
$off_activity = Config::where('name', 'off_activity')->value('value');
if($off_activity==1){
$data=[
'off_activity' => $off_activity,
'price' => 'cost',
'op_price' => 'price',
];
}else{
$data=[
'off_activity' => $off_activity,
'price' => 'price',
'op_price' => 'price',
];
}
return $data;
}
} }

View File

@ -10,6 +10,7 @@ use app\common\logic\BaseLogic;
use app\common\logic\CapitalFlowLogic; use app\common\logic\CapitalFlowLogic;
use app\common\logic\PayNotifyLogic; use app\common\logic\PayNotifyLogic;
use app\common\logic\StoreFinanceFlowLogic; use app\common\logic\StoreFinanceFlowLogic;
use app\common\model\Config;
use app\common\model\dict\DictData; use app\common\model\dict\DictData;
use app\common\model\dict\DictType; use app\common\model\dict\DictType;
use app\common\model\order\Cart; use app\common\model\order\Cart;
@ -24,6 +25,7 @@ use app\common\model\system_store\SystemStoreStaff;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\user\UserAddress; use app\common\model\user\UserAddress;
use app\common\model\user\UserShip; use app\common\model\user\UserShip;
use app\common\model\user_sign\UserSign;
use app\common\model\user_spread_log\UserSpreadLog; use app\common\model\user_spread_log\UserSpreadLog;
use Picqer\Barcode\BarcodeGeneratorJPG; use Picqer\Barcode\BarcodeGeneratorJPG;
use Picqer\Barcode\BarcodeGeneratorPNG; use Picqer\Barcode\BarcodeGeneratorPNG;
@ -72,46 +74,38 @@ class OrderLogic extends BaseLogic
self::$activity_price = 0; //活动减少 self::$activity_price = 0; //活动减少
self::$store_price = 0; //门店零售价 self::$store_price = 0; //门店零售价
/** 计算价格 */ /** 计算价格 */
$off_activity=Config::where('name','off_activity')->value('value');
$field='id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id';
foreach ($cart_select as $k => $v) { foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field('id branch_product_id,store_name,image,unit,cost price,vip_price,cost,purchase,product_id')->withTrashed()->find(); $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->withTrashed()->find();
if (!$find) { if (!$find) {
continue; continue;
} }
unset($cart_select[$k]['id']); unset($cart_select[$k]['id']);
if($off_activity==1){
$cart_select[$k]['price'] = $find['price']; $price=$find['cost'];
}else{
$price=$find['price'];
}
$cart_select[$k]['price'] = $price;
$cart_select[$k]['cost'] = $find['cost']; $cart_select[$k]['cost'] = $find['cost'];
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额 $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
$cart_select[$k]['vip'] = 0; $cart_select[$k]['vip'] = 0;
// if ($user && $user['user_ship'] == 1) {
// //更新 会员为1的时候原价减去会员价
// $deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2);
// $cart_select[$k]['deduction_price'] =$deduction_price_count;
// self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
// $cart_select[$k]['vip'] =1;
// }
// if ($user && $user['user_ship'] == 4) {
// //更新 为4商户的时候减去商户价格
// $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
// $cart_select[$k]['deduction_price'] =$deduction_price_count;
// self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
// }
//利润 //利润
// $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
$cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额 $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]['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]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id']; $cart_select[$k]['old_cart_id'] = $v['id'];
$cart_select[$k]['cart_num'] = $v['cart_num']; $cart_select[$k]['cart_num'] = $v['cart_num'];
$cart_select[$k]['verify_code'] = $params['verify_code'] ?? ''; $cart_select[$k]['verify_code'] = $params['verify_code'] ?? '';
//vip1待返回金额 //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'] ); // d($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],$cart_select[$k]['vip_price'] );
$cartInfo = $cart_select[$k]; $cartInfo = $cart_select[$k];
$cartInfo['name'] = $find['store_name']; $cartInfo['name'] = $find['store_name'];
@ -147,7 +141,6 @@ class OrderLogic extends BaseLogic
'order_id' => $params['order_id'] ?? getNewOrderId('PF'), 'order_id' => $params['order_id'] ?? getNewOrderId('PF'),
'total_price' => self::$total_price, //总价 'total_price' => self::$total_price, //总价
'cost' => self::$cost, //成本价1- 'cost' => self::$cost, //成本价1-
'profit' =>0, //利润
'pay_price' => $pay_price, //后期可能有降价抵扣 'pay_price' => $pay_price, //后期可能有降价抵扣
'vip_price' => 0, 'vip_price' => 0,
'total_num' => count($cart_select), //总数 'total_num' => count($cart_select), //总数
@ -161,6 +154,7 @@ class OrderLogic extends BaseLogic
'activities' => self::$activity_price>0?1:0, 'activities' => self::$activity_price>0?1:0,
'deduction_price' => self::$activity_price, 'deduction_price' => self::$activity_price,
'is_vip' => 0, 'is_vip' => 0,
'is_storage' => $params['is_storage']??0,
]; ];
$order['default_delivery'] = 0; $order['default_delivery'] = 0;
if ($params['store_id']) { if ($params['store_id']) {
@ -192,11 +186,12 @@ class OrderLogic extends BaseLogic
if (!$orderInfo) { if (!$orderInfo) {
return false; return false;
} }
$uid=$user['id']??0;
$_order = $orderInfo['order']; $_order = $orderInfo['order'];
$_order['uid'] = $user['id']; $_order['uid'] = $uid;
$_order['spread_uid'] =$params['spread_uid']??0; $_order['spread_uid'] =$params['spread_uid']??0;
$_order['real_name'] = $user['real_name']; $_order['real_name'] = $user['real_name']??'';
$_order['mobile'] = $user['mobile']; $_order['mobile'] = $user['mobile']??'';
$_order['pay_type'] = $orderInfo['order']['pay_type']; $_order['pay_type'] = $orderInfo['order']['pay_type'];
$_order['verify_code'] = $verify_code; $_order['verify_code'] = $verify_code;
$_order['reservation_time'] = null; $_order['reservation_time'] = null;
@ -204,8 +199,8 @@ class OrderLogic extends BaseLogic
$_order['reservation_time'] = $params['reservation_time']; $_order['reservation_time'] = $params['reservation_time'];
$_order['reservation'] = YesNoEnum::YES; $_order['reservation'] = YesNoEnum::YES;
} }
if ($addressId > 0) { if ($addressId > 0 &&$uid>0 ) {
$address = UserAddress::where(['id' => $addressId, 'uid' => $user['id']])->find(); $address = UserAddress::where(['id' => $addressId, 'uid' => $uid])->find();
if ($address) { if ($address) {
$_order['real_name'] = $address['real_name']; $_order['real_name'] = $address['real_name'];
$_order['user_phone'] = $address['phone']; $_order['user_phone'] = $address['phone'];
@ -228,7 +223,7 @@ class OrderLogic extends BaseLogic
$goods_list = $orderInfo['cart_list']; $goods_list = $orderInfo['cart_list'];
foreach ($goods_list as $k => $v) { foreach ($goods_list as $k => $v) {
$goods_list[$k]['oid'] = $order->id; $goods_list[$k]['oid'] = $order->id;
$goods_list[$k]['uid'] = $user['id']; $goods_list[$k]['uid'] = $uid;
$goods_list[$k]['cart_id'] = implode(',', $cartId); $goods_list[$k]['cart_id'] = implode(',', $cartId);
$goods_list[$k]['delivery_id'] = $params['store_id']; //商家id $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id
$StoreBranchProduct = StoreBranchProduct::where('id',$v['branch_product_id'])->withTrashed()->find(); $StoreBranchProduct = StoreBranchProduct::where('id',$v['branch_product_id'])->withTrashed()->find();
@ -442,11 +437,17 @@ class OrderLogic extends BaseLogic
$order=StoreOrder::where('id',$data['id'])->find(); $order=StoreOrder::where('id',$data['id'])->find();
PayNotifyLogic::afterPay($order); PayNotifyLogic::afterPay($order);
PayNotifyLogic::descStock($order['id']); PayNotifyLogic::descStock($order['id']);
if($order['uid'] && $order['total_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]);
}
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
d($e);
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }

View File

@ -12,15 +12,13 @@ class StoreLogic extends BaseLogic
public static function search($param) public static function search($param)
{ {
return SystemStore::where($param) $data = SystemStore::where($param)
->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show', ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show',
'day_time', 'is_store', 'latitude', 'longitude', 'day_start', 'day_end', 'is_store' 'day_time', 'is_store', 'latitude', 'longitude', 'day_start', 'day_end', 'is_store'
, 'is_send' , 'is_send'
]) ])
->find() ->find();
->toArray(); return $data ? $data->toArray() : [];
} }

View File

@ -59,8 +59,8 @@ class AddressLogic extends BaseLogic
{ {
Db::startTrans(); Db::startTrans();
try { try {
$is_default = $params['is_default']??0; $is_default = $params['is_default'] ??0;
if($is_default){ if($is_default==1){
UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]); UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]);
} }
$data = [ $data = [
@ -68,6 +68,8 @@ class AddressLogic extends BaseLogic
'phone' => $params['phone'], 'phone' => $params['phone'],
'detail' => $params['detail']??'', 'detail' => $params['detail']??'',
'is_default' => $params['is_default']??0, 'is_default' => $params['is_default']??0,
'detail' => $params['detail']??'',
'is_default' => $params['is_default']??0,
'province' => $params['province'], 'province' => $params['province'],
'city' => $params['city'], 'city' => $params['city'],
'area' => $params['area'], 'area' => $params['area'],
@ -111,6 +113,7 @@ class AddressLogic extends BaseLogic
return UserAddress::field('id,real_name,phone,province,city,area,street,village,brigade,detail,is_default')->where('id',$params['address_id'])->findOrEmpty()->toArray(); return UserAddress::field('id,real_name,phone,province,city,area,street,village,brigade,detail,is_default')->where('id',$params['address_id'])->findOrEmpty()->toArray();
} }
public static function info($params): array public static function info($params): array
{ {
return UserAddress::field('id,real_name,phone,province,city,area,street,village,brigade,detail,is_default')->where($params)->findOrEmpty()->toArray(); return UserAddress::field('id,real_name,phone,province,city,area,street,village,brigade,detail,is_default')->where($params)->findOrEmpty()->toArray();

View File

@ -3,6 +3,7 @@
namespace app\api\logic\user; namespace app\api\logic\user;
use app\api\service\UserTokenService;
use app\common\{logic\BaseLogic, use app\common\{logic\BaseLogic,
model\dict\DictData, model\dict\DictData,
model\finance\CapitalFlow, model\finance\CapitalFlow,
@ -53,8 +54,15 @@ class UserLogic extends BaseLogic
['id', '<>', $params['user_id']] ['id', '<>', $params['user_id']]
])->findOrEmpty(); ])->findOrEmpty();
if (!$user->isEmpty()) { if (!$user->isEmpty()) {
throw new \Exception('手机号已被其他账号绑定'); //切换被绑定账号删除该账号并且以新的账号登录
UserAuth::where('user_id',$params['user_id'])->update([
'user_id'=>$user['id']
]);
User::destroy($params['user_id']);
return $user['id'];
// throw new \Exception('手机号已被其他账号绑定');
} }
// 绑定手机号 // 绑定手机号
@ -105,6 +113,12 @@ class UserLogic extends BaseLogic
'is_writeoff'=>0,'uid'=>$uid 'is_writeoff'=>0,'uid'=>$uid
])->whereIn('shipping_type',[1,2])->count(); ])->whereIn('shipping_type',[1,2])->count();
$data['openid'] = UserAuth::where(['user_id'=>$uid,'terminal'=>1])->value('openid'); $data['openid'] = UserAuth::where(['user_id'=>$uid,'terminal'=>1])->value('openid');
$number=UserSign::where('uid',$uid)->where('status',0)->sum('number');
$data['integral']=bcadd($data['integral'],$number,2);
$number = UserSign::where('uid',$uid)->where('status',0)->sum('number');
$GetNumber = UserSign::where('uid',$uid)->where('status',1)->sum('number');
$data['number'] =bcadd($number,0,2);
$data['GetNumber'] =bcadd($GetNumber,0,2);
}else{ }else{
$data = []; $data = [];
} }
@ -209,6 +223,22 @@ class UserLogic extends BaseLogic
} }
public function dealReportingSms($phone,$string = '_reporting')
{
$code = generateRandomCode();
$template = getenv('SMS_LOGIN_TEMPLATE');
$check =(new SmsService())->client($phone,$template,$code);
if($check){
$remark = $phone.$string;
Cache::set($remark,$code,5*60);
return true;
}else{
return false;
}
}
public static function dealPayPassword($params,$uid) public static function dealPayPassword($params,$uid)
@ -272,10 +302,10 @@ class UserLogic extends BaseLogic
//礼品券明细 //礼品券明细
$query = UserSign::where(['uid'=>$uid]); $query = UserSign::where(['uid'=>$uid]);
if($params['mark'] == 1){ if($params['mark'] == 1){
$query->where('financial_pm',1); $query->where('financial_pm',0);
} }
if($params['mark'] == 2){ if($params['mark'] == 2){
$query->where('financial_pm',0); $query->where('financial_pm',1);
} }
$count = $query->count(); $count = $query->count();
$data =$query $data =$query
@ -287,10 +317,10 @@ class UserLogic extends BaseLogic
//返还金明细 -todo back //返还金明细 -todo back
$query = VipFlow::with('store')->where(['user_id'=>$uid]); $query = VipFlow::with('store')->where(['user_id'=>$uid]);
if($params['mark'] == 1){ if($params['mark'] == 1){
$query->where('status',1); $query->where('status',0);
} }
if($params['mark'] == 2){ if($params['mark'] == 2){
$query->where('status',0); $query->where('status',1);
} }
$count = $query->count(); $count = $query->count();
$data = $query $data = $query

View File

@ -4,6 +4,7 @@
namespace app\api\validate; namespace app\api\validate;
use app\common\model\auth\Admin;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
/** /**
@ -19,8 +20,8 @@ class UserValidate extends BaseValidate
'store_id' => 'require', 'store_id' => 'require',
'mobile' => 'require', 'mobile' => 'require',
'phone' => 'require|number', 'phone' => 'require|number',
'password' => 'require', 'password' => 'require|length:6',
'rePassword' => 'require', 'rePassword' => 'require|requireWith:password|confirm:password',
'type' => 'require', 'type' => 'require',
'account' => 'require', 'account' => 'require',
@ -32,8 +33,8 @@ class UserValidate extends BaseValidate
'mobile.require' => '手机', 'mobile.require' => '手机',
'phone.require' => '手机', 'phone.require' => '手机',
'account.require' => '手机', 'account.require' => '手机',
'password.require' => '密码', 'password.require' => '密码缺失',
'rePassword.require' => '确认密码', 'rePassword.require' => '确认密码缺失',
'type' => '查询类型', 'type' => '查询类型',
]; ];

View File

@ -46,6 +46,7 @@ class OrderEnum
const CASHIER_FACE_PAY = 17;//现金收银 const CASHIER_FACE_PAY = 17;//现金收银
const PURCHASE_FUNDS = 18;//采购款收银 const PURCHASE_FUNDS = 18;//采购款收银
const PAY_BACK =-1;
/** /**
@ -183,10 +184,10 @@ class OrderEnum
public static function getOrderType($value = true) public static function getOrderType($value = true)
{ {
$data = [ $data = [
self::RECEIVED_GOODS => '已收货', self::RECEIVED_GOODS => '已完成',
self::WAIT_EVALUATION => '待评价', self::WAIT_EVALUATION => '待评价',
self::WAIT_DELIVERY => '待发货', self::WAIT_DELIVERY => '待发货',
self::WAIT_RECEIVING => '待收货', self::WAIT_RECEIVING => '待核销',
self::RETURN_SUCCESS => '退货成功', self::RETURN_SUCCESS => '退货成功',
self::ALREADY_REFUND => '已退款', self::ALREADY_REFUND => '已退款',
self::RECEIVED_BACK => '已退款', self::RECEIVED_BACK => '已退款',

View File

@ -22,23 +22,6 @@ trait ListsSearchTrait
return []; return [];
} }
$where = []; $where = [];
$class_key = $this->request->__get('class_key');
if ($class_key !== null) {
foreach ($class_key as $key => $value) {
if (isset($search[$key])) {
foreach ($value as $v) { // 遍历class_key的值添加到search数组中
array_push($search[$key], $v); // 添加class_key的搜索条件
}
} else {
$search[$key] = [$value[0]]; // 创建新的搜索条件
}
}
}
$class_value = $this->request->__get('class_value'); // 获取class_value的值
if ($class_value !== null) {
$this->params = array_merge($this->params, $class_value);
}
foreach ($search as $whereType => $whereFields) { foreach ($search as $whereType => $whereFields) {
switch ($whereType) { switch ($whereType) {
case '=': case '=':

View File

@ -0,0 +1,195 @@
<?php
namespace app\common\logic;
use app\common\enum\OrderEnum;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
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) {
$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.03, $transaction_id,$village_uid,12);//会员
self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
self::user($order, 0.01, $transaction_id,0,16);//其他
}
/**
* 走队长分润
*/
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) {
$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.03, $transaction_id,$village_uid,12);//会员
self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
self::user($order, 0.01, $transaction_id,0,16);//其他
}
/**
* 走厨师分润
*/
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) {
$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.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);//其他
}
/**
* 走线下分润
*/
public static function setStore($order, $transaction_id)
{
self::platform($order, 0.05, $transaction_id);//平台
self::store($order, 0.02, $transaction_id,0);//门店
self::user($order, 0.01, $transaction_id,0,16);//其他
}
/**
* 平台分润
*/
public static function platform($order, $platformRate, $transaction_id)
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order=$order;
$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']); //商户平台手续费支出
}
}
/**
* 门店分润
*/
public static function store($order, $platformRate, $transaction_id,$uid)
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->user['uid']=$order['uid'];
$financeLogic->other_arr['vip_uid']=$uid;
$financeLogic->order=$order;
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付
//缴纳齐全了就加商户没有就加到平台
$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);
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']); //平台手续费
}
}
} 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']); //平台手续费
}
}
}
/**
* 分给用户
*/
public static function user($order, $userRate, $transaction_id,$uid=0,$enum = 0)
{
$financeLogic = new StoreFinanceFlowLogic();
$fees = bcmul($order['pay_price'], $userRate, 2);
if ($fees > 0) {
//记录用户余额收入
if ($uid) {
$GiveUser = User::where('id', $order['uid'])->find();
$capitalFlowDao = new CapitalFlowLogic($GiveUser);
$capitalFlowDao->userIncome('system_balance_add', 'order', $order['id'], $fees);
}
$financeLogic->user['uid']=$order['uid'];
$financeLogic->other_arr['vip_uid']=$uid;
$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']);
}
}
}

View File

@ -7,6 +7,8 @@ use app\common\enum\OrderEnum;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
use app\common\enum\user\UserShipEnum; use app\common\enum\user\UserShipEnum;
use app\common\enum\YesNoEnum; use app\common\enum\YesNoEnum;
use app\common\logic\user_product_storage\UserProductStorageLogic;
use app\common\model\Config;
use app\common\model\dict\DictType; use app\common\model\dict\DictType;
use app\common\model\finance\CapitalFlow; use app\common\model\finance\CapitalFlow;
use app\common\model\finance\PayNotifyLog; use app\common\model\finance\PayNotifyLog;
@ -40,14 +42,6 @@ class PayNotifyLogic extends BaseLogic
{ {
Db::startTrans(); Db::startTrans();
try { try {
if ($action != 'cash_pay' && $action != 'balancePay' && $action != 'purchase_funds' && $action != 'gift_pay') {
$payNotifyLogLogic = new PayNotifyLogLogic();
if ($action == 'refund') {
$payNotifyLogLogic->insert($action, $extra, PayNotifyLog::TYPE_REFUND);
} else {
$payNotifyLogLogic->insert($action, $extra);
}
}
self::$action($orderSn, $extra, $type); self::$action($orderSn, $extra, $type);
Db::commit(); Db::commit();
return true; return true;
@ -80,6 +74,10 @@ class PayNotifyLogic extends BaseLogic
if (!$order->save()) { if (!$order->save()) {
throw new \Exception('订单保存出错'); throw new \Exception('订单保存出错');
} }
if($order['is_storage']==1){
$order->status=2;
UserProductStorageLogic::add($order);
}
// 减去余额 // 减去余额
$user->now_money = bcsub($user['now_money'], $order['pay_price'], 2); $user->now_money = bcsub($user['now_money'], $order['pay_price'], 2);
$user->save(); $user->save();
@ -90,6 +88,7 @@ class PayNotifyLogic extends BaseLogic
$order['pay_price'] = $oldUser; $order['pay_price'] = $oldUser;
} }
} }
self::addUserSing($order);
$capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']); $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']);
self::dealProductLog($order); self::dealProductLog($order);
@ -173,6 +172,10 @@ class PayNotifyLogic extends BaseLogic
if (!$order->save()) { if (!$order->save()) {
throw new \Exception('订单保存出错'); throw new \Exception('订单保存出错');
} }
if($order['is_storage']==1){
$order->status=2;
UserProductStorageLogic::add($order);
}
// 减去采购款 // 减去采购款
$user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2); $user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2);
$user->save(); $user->save();
@ -182,7 +185,7 @@ class PayNotifyLogic extends BaseLogic
// if ($user['user_ship'] == 1) { // if ($user['user_ship'] == 1) {
// self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS); // self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS);
// } // }
self::addUserSing($order);
if ($extra && $extra['store_id']) { if ($extra && $extra['store_id']) {
$params = [ $params = [
'verify_code' => $order['verify_code'], 'verify_code' => $order['verify_code'],
@ -214,12 +217,15 @@ class PayNotifyLogic extends BaseLogic
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
return true; return true;
} }
$order->status = 1;
$order->paid = 1;
$order->pay_time = time();
if($order['is_storage']==1){
$order->status=2;
UserProductStorageLogic::add($order);
}
if ($order->pay_type != 10) { if ($order->pay_type != 10) {
$order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2); $order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2);
$order->paid = 1;
$order->pay_time = time();
$order->status = 1;
$order->save();
} else { } else {
$extra['transaction_id'] = time(); $extra['transaction_id'] = time();
} }
@ -232,21 +238,11 @@ class PayNotifyLogic extends BaseLogic
//微信支付和用户余额无关 //微信支付和用户余额无关
$capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price, '', 1, $order['store_id']); $capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price, '', 1, $order['store_id']);
} }
$order->save();
self::dealProductLog($order); self::dealProductLog($order);
if ($order['shipping_type'] == 3) { if ($order['shipping_type'] == 3) {
self::descStock($order['id']); self::descStock($order['id']);
} }
// if ($order->pay_type == 9) {
// $extra['create_time'] = $order['create_time'];
// PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]);
// Redis::send('push-platform-print', ['id' => $order['id']]);
// }
// else {
// PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
// Db::name('order_middle')->insert(['c_order_id' => $order['id']]);
// }
if (!empty($extra['payer']['openid']) && $order->pay_type == 7) { if (!empty($extra['payer']['openid']) && $order->pay_type == 7) {
Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid']], 4); Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid']], 4);
} }
@ -259,6 +255,17 @@ class PayNotifyLogic extends BaseLogic
//更新状态 //更新状态
$order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) {
//充值
$orderRe = UserRecharge::where('order_id', $orderSn)->findOrEmpty();
if ($orderRe->isEmpty() || $orderRe->status == -1) {
return true;
}
$orderRe->status = -1;
$orderRe->refund_price = $orderRe->price;
$orderRe->refund_time = time();
$orderRe->remarks = '';
$orderRe->save();
return true; return true;
} }
$order->status = OrderEnum::REFUND_PAY; $order->status = OrderEnum::REFUND_PAY;
@ -272,6 +279,8 @@ class PayNotifyLogic extends BaseLogic
$user = User::where('id', $order['uid'])->findOrEmpty(); $user = User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao = new CapitalFlowLogic($user);
$deal_money = bcdiv($extra['amount']['refund'], 100, 2); $deal_money = bcdiv($extra['amount']['refund'], 100, 2);
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额 if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额
$user->now_money = bcadd($user->now_money, $deal_money, 2); $user->now_money = bcadd($user->now_money, $deal_money, 2);
@ -281,6 +290,7 @@ class PayNotifyLogic extends BaseLogic
//退款 //退款
$capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money); $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) { //采购款 if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款
$user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2); $user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2);
$user->save(); $user->save();
@ -292,11 +302,37 @@ class PayNotifyLogic extends BaseLogic
} }
//微信日志 user_order_refund //微信日志 user_order_refund
$capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1); $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1);
//处理财务流水退还
self::store_finance_back($orderSn);
self::addStock($order['id']); //微信 self::addStock($order['id']); //微信
return true;
// self::afterPay($order,$extra['transaction_id']); // self::afterPay($order,$extra['transaction_id']);
} }
/**
* 财务退还金额相关
* @param $orderSn
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function store_finance_back($orderSn)
{
$data = StoreFinanceFlow::where('order_sn', $orderSn)
->where(['financial_pm' => 1])
->select()->toArray();
foreach ($data as &$value) {
unset($value['id']);
$value['financial_record_sn'] = (new StoreFinanceFlowLogic)->getSn();
$value['financial_pm'] = 0;
$value['financial_type'] = OrderEnum::PAY_BACK;
$value['create_time'] = time();
}
(new StoreFinanceFlow)->saveAll($data);
}
/** /**
* 现金退款相关 * 现金退款相关
* @param $orderSn * @param $orderSn
@ -320,6 +356,7 @@ class PayNotifyLogic extends BaseLogic
//日志记录 //日志记录
$model = new StoreCashFinanceFlow(); $model = new StoreCashFinanceFlow();
$model->store_id = $order['store_id'] ?? 0; $model->store_id = $order['store_id'] ?? 0;
$model->store_id = $order['store_id'] ?? 0;
$model->cash_price = $order->pay_price; $model->cash_price = $order->pay_price;
$model->receivable = $order->pay_price; $model->receivable = $order->pay_price;
$model->remark = '退款'; $model->remark = '退款';
@ -331,6 +368,45 @@ class PayNotifyLogic extends BaseLogic
return true; return true;
} }
/**
* 充值现金退款相关
* @param $orderId
* @param $extra
* @return true
*/
public static function recharge_cash_refund($orderId, $extra = [])
{
$order = UserRecharge::where('id', $orderId)->findOrEmpty();
if ($order->isEmpty() || $order->status == -1) {
return true;
}
$order->status = -1;
$order->refund_price = $order->price;
$order->refund_time = time();
$order->remarks = '';
$order->save();
return true;
}
//入冻结礼品券
public static function addUserSing($order)
{
$user_sing = new UserSign();
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' => '购买商品获得兑换券',
'store_id' => $order['store_id'],
'number' => $user_number,
];
$user_sing->save($sing);
}
return true;
}
/** /**
* 充值 * 充值
*/ */
@ -361,14 +437,17 @@ class PayNotifyLogic extends BaseLogic
bcscale(2); bcscale(2);
// $user->now_money = bcadd($user->now_money, $price, 2);//v.1 // $user->now_money = bcadd($user->now_money, $price, 2);//v.1
//更新等级 //更新等级
if ($price >= 0.01) { if ($price >= Config::where('name','recharge')->value('value')) {
$user->user_ship = 1; //v.1 $user->user_ship = 1; //v.1
} }
$user->purchase_funds = bcadd($user->purchase_funds, $price, 2); $user->purchase_funds = bcadd($user->purchase_funds, $price, 2);
$user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2);
$user->save(); $user->save();
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]]);
if (!empty($extra['payer']['openid'])) { if (!empty($extra['payer']['openid'])) {
Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4); Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4);
} }
@ -399,6 +478,7 @@ class PayNotifyLogic extends BaseLogic
self::descStock($order['id']); self::descStock($order['id']);
} }
// Redis::send('push-platform-print', ['id' => $order['id']]); // Redis::send('push-platform-print', ['id' => $order['id']]);
return true;
} }
/** /**
@ -453,24 +533,28 @@ class PayNotifyLogic extends BaseLogic
{ {
$financeLogic = new StoreFinanceFlowLogic(); $financeLogic = new StoreFinanceFlowLogic();
$user_sing = new UserSign(); $user_sing = new UserSign();
//-----活动价结算更改 $off_activity = Config::where('name', 'off_activity')->value('value');
$financeLogic->order = $order; if ($off_activity == 1) {
$financeLogic->user = ['uid' => $order['uid']]; //-----活动价结算更改
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 $financeLogic->order = $order;
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); $financeLogic->user = ['uid' => $order['uid']];
$financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付
if ($order['uid'] > 0) { $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
$user_number = bcmul($order['pay_price'], '0.10', 2); $financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
$sing = [ if ($order['uid'] > 0 && $order['total_price'] > 500 && $order['pay_type'] !=18
'uid' => $order['uid'], && $order['pay_type'] !=3) {
'order_id' => $order['order_id'], $user_number = bcmul($order['pay_price'], '0.10', 2);
'title' => '购买商品获得兑换券', $sing = [
'store_id' => $order['store_id'], 'uid' => $order['uid'],
'number' => $user_number, 'order_id' => $order['order_id'],
]; 'title' => '购买商品获得兑换券',
$user_sing->save($sing); 'store_id' => $order['store_id'],
'number' => $user_number,
];
$user_sing->save($sing);
}
return false;
} }
return false;
$vipFen = 0; $vipFen = 0;
if ($order['uid'] > 0) { if ($order['uid'] > 0) {
// 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去
@ -492,17 +576,21 @@ class PayNotifyLogic extends BaseLogic
$order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2); $order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2);
self::dealVipAmount($order, $order['pay_type']); self::dealVipAmount($order, $order['pay_type']);
} }
if($order['total_price'] > 500 && $order['pay_type'] !=18
&& $order['pay_type'] !=3){
$user_number = bcmul($order['pay_price'], '0.10', 2);
$sing = [
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '购买商品获得兑换券',
'store_id' => $order['store_id'],
'number' => $user_number,
'status' => 0,
];
$user_sing->save($sing);
}
$user_number = bcmul($order['pay_price'], '0.10', 2); // User::where('id', $order['uid'])->inc('integral', $user_number)->update();
$sing = [
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'title' => '购买商品获得兑换券',
'store_id' => $order['store_id'],
'number' => $user_number,
];
$user_sing->save($sing);
User::where('id', $order['uid'])->inc('integral', $user_number)->update();
} }
@ -852,6 +940,7 @@ class PayNotifyLogic extends BaseLogic
'id' => $StoreBranchProduct['id'], 'id' => $StoreBranchProduct['id'],
'stock' => $StoreBranchProduct['stock'] + $v['cart_num'], 'stock' => $StoreBranchProduct['stock'] + $v['cart_num'],
// 'sales' => ['inc', $v['cart_num']] // 'sales' => ['inc', $v['cart_num']]
// 'sales' => ['inc', $v['cart_num']]
]; ];
} }
} }

View File

@ -53,7 +53,7 @@ class StoreFinanceFlowLogic extends BaseLogic
'order_id' => $this->order['id'], 'order_id' => $this->order['id'],
'transaction_id' => $transaction_id, 'transaction_id' => $transaction_id,
'order_sn' => $this->order['order_id'], 'order_sn' => $this->order['order_id'],
'user_id' => $this->user['uid'], 'user_id' => $this->user['uid']??0,
'other_uid' => $this->other_arr['vip_uid']??0, 'other_uid' => $this->other_arr['vip_uid']??0,
'financial_type' => $financialType, 'financial_type' => $financialType,
'financial_pm' => $pm, 'financial_pm' => $pm,

View File

@ -19,6 +19,7 @@ use app\common\service\SmsService;
use Exception; use Exception;
use support\Cache; use support\Cache;
use think\facade\Db; use think\facade\Db;
use app\common\model\system_store\SystemStore;
class StoreOrderLogic extends BaseLogic class StoreOrderLogic extends BaseLogic
{ {
@ -32,6 +33,11 @@ class StoreOrderLogic extends BaseLogic
* @notes 获取购物车商品信息 * @notes 获取购物车商品信息
* @param $params * @param $params
* @return array|bool * @return array|bool
*/
/**
* @notes 获取购物车商品信息
* @param $params
* @return array|bool
*/ */
static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = []) static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [])
{ {
@ -45,14 +51,19 @@ class StoreOrderLogic extends BaseLogic
try { try {
self::$total_price = 0; self::$total_price = 0;
self::$pay_price = 0; self::$pay_price = 0;
self::$cost = 0; //成本 self::$cost = 0; //成本由采购价替代原成本为门店零售价
self::$profit = 0; //利润 self::$profit = 0; //利润
self::$activity_price = 0; //活动减少 self::$activity_price = 0; //活动减少
self::$store_price = 0; //门店零售价 self::$store_price = 0; //门店零售价
/** 计算价格 */ /** 计算价格 */
$pay_type = isset($params['pay_type'])?$params['pay_type']:0; // $off_activity=Config::where('name','off_activity')->value('value');
// if($off_activity==1){
// $field='id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id';
// }else{
$field='id branch_product_id,store_name,image,unit,cost price,vip_price,cost,purchase,product_id';
// }
foreach ($cart_select as $k => $v) { foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field('id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,swap')->withTrashed()->find(); $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->withTrashed()->find();
if (!$find) { if (!$find) {
continue; continue;
} }
@ -63,47 +74,39 @@ class StoreOrderLogic extends BaseLogic
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额 $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
$cart_select[$k]['vip'] = 0; $cart_select[$k]['vip'] = 0;
if ($user && $user['user_ship'] == 1) { // if($off_activity!=1){
//更新 会员为1的时候原价减去会员价 // if ($user && $user['user_ship'] == 1) {
$deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2); // //更新 会员为1的时候原价减去会员价
$cart_select[$k]['deduction_price'] =$deduction_price_count; // $deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2);
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); // $cart_select[$k]['deduction_price'] =$deduction_price_count;
$cart_select[$k]['vip'] =1; // self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
} // $cart_select[$k]['vip'] =1;
// }
// if ($user && $user['user_ship'] == 4) {
// //更新 为4商户的时候减去商户价格
// $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
// $cart_select[$k]['deduction_price'] =$deduction_price_count;
// self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
// }
// }
if ($user && $user['user_ship'] == 4) {
//更新 为4商户的时候减去商户价格
$deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
}
if($pay_type ==19){
if ($find['swap'] < $cart_select[$k]['cart_num']) {
throw new \Exception('兑换数量不足');
}
}
//利润 //利润
// $cart_select[$k]['profit'] = bcmul($cart_select[$k]['total_price'],0.05,2); //利润 // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
$cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额 $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
$cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2)??0; //门店零售价 $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]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id']; $cart_select[$k]['old_cart_id'] = $v['id'];
$cart_select[$k]['cart_num'] = $v['cart_num']; $cart_select[$k]['cart_num'] = $v['cart_num'];
$cart_select[$k]['verify_code'] = $params['verify_code'] ?? ''; $cart_select[$k]['verify_code'] = $params['verify_code'] ?? '';
//vip1待返回金额 //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 = $cart_select[$k];
$cartInfo['name'] = $find['store_name']; $cartInfo['name'] = $find['store_name'];
$cartInfo['image'] = $find['image']; $cartInfo['image'] = $find['image'];
//计算好vip价格
// $vipPrice = self::dealVip($find['price']);
// if ($vipPrice) {
// $cartInfo['price'] = $vipPrice;
// }
//$cart_select[$k]['total'] - $vipPrice ?? 0;
$cart_select[$k]['cart_info'] = json_encode($cartInfo); $cart_select[$k]['cart_info'] = json_encode($cartInfo);
$cart_select[$k]['branch_product_id'] = $find['branch_product_id']; $cart_select[$k]['branch_product_id'] = $find['branch_product_id'];
//理论上每笔都是拆分了 //理论上每笔都是拆分了
@ -113,53 +116,52 @@ class StoreOrderLogic extends BaseLogic
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2); self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2);
self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2); self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2);
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2); self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2);
self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2);//门店零售价格 self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2);//门店零售价格
// self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
} }
if ($user && $user['user_ship'] == 1 && $pay_type !=17) { //加支付方式限制
$pay_price = self::$pay_price; // $pay_type = isset($params['pay_type'])?$params['pay_type']:0;
$activity_string = ''; // if ($user && $user['user_ship'] == 1 && $pay_type !=17) {
}else{ // $pay_price = self::$pay_price;
$pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 // }else{
$activity_string = '减免'; // $pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
} // }
if($pay_type == 19){ $pay_price = self::$pay_price;
$pay_price = self::$pay_price;
$activity_string = '';
}
// if($pay_price < 500){ // if($pay_price < 500){
// throw new \think\Exception('金额低于500'); // throw new Exception('金额低于500');
// } // }
$vipPrice = 0;
//成本价 收益 //成本价 收益
$order = [ $order = [
'create_time' => time(), 'create_time' => time(),
'order_id' =>$params['order_id'] ?? getNewOrderId('PF'), 'order_id' => $params['order_id'] ?? getNewOrderId('PF'),
'total_price' => self::$total_price, //总价 'total_price' => self::$total_price, //总价
'cost' => self::$cost,//成本价 'cost' => self::$cost, //成本价1-
'profit' => 0,//利润 'pay_price' => $pay_price, //后期可能有降价抵扣
'pay_price' => $pay_price,//后期可能有降价抵扣 'vip_price' => 0,
'vip_price' => $vipPrice, 'total_num' => count($cart_select), //总数
'total_num' => count($cart_select),//总数
'pay_type' => $params['pay_type'] ?? 0, 'pay_type' => $params['pay_type'] ?? 0,
'reservation_time' => $params['reservation_time'] ?? null, 'reservation_time' => $params['reservation_time'] ?? null,
'cart_id' => implode(',', $cartId), 'cart_id' => implode(',', $cartId),
'store_id' => $params['store_id'] ?? 0, 'store_id' => $params['store_id'] ?? 0,
'shipping_type' =>3,//配送方式 1=快递 2=门店自提 'shipping_type' => $params['shipping_type'] ?? 2, //配送方式 1=快递 2=门店自提
'activity' =>$activity_string, 'activity' => '减免',
'activity_price' =>self::$activity_price,//活动优惠价 'activity_price' => self::$activity_price,
'activities' => self::$activity_price>0?1:0, 'activities' => self::$activity_price>0?1:0,
'default_delivery'=>1, 'deduction_price' => self::$activity_price,
'original_price'=>self::$total_price, 'is_vip' => 0,
'deduction_price' => self::$activity_price,//抵扣金额 'is_storage' => $params['is_storage']??0,
]; ];
if($user && $user['user_ship']!=4){ $order['default_delivery'] = 0;
$order['is_vip']=1; if ($params['store_id']) {
$order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send');
} }
if($user && $user['user_ship']>=1 &&$user['user_ship']<=3){
$order['is_vip'] = 1;
}
} catch (\Exception $e) { } catch (\Exception $e) {
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
@ -256,12 +258,16 @@ class StoreOrderLogic extends BaseLogic
$pageNo = $params['page_no']; $pageNo = $params['page_no'];
$pageSize = $params['page_size']; $pageSize = $params['page_size'];
unset($params['page_no'],$params['page_size']); unset($params['page_no'],$params['page_size']);
if($params['verify_code']==''){
unset($params['verify_code']);
}
$params['paid'] = YesNoEnum::YES; $params['paid'] = YesNoEnum::YES;
$params['is_writeoff'] = YesNoEnum::YES; $params['is_writeoff'] = YesNoEnum::YES;
$order = StoreOrder::with(['user', 'staff', 'product' => function ($query) { $order = StoreOrder::with(['user', 'staff', 'product' => function ($query) {
$query->field(['id', 'oid', 'product_id', 'cart_info']); $query->field(['id', 'oid', 'product_id', 'cart_info']);
}])->where($params)->whereIn('shipping_type',OrderEnum::ONLINE) }])->where($params)
->page($pageNo, $pageSize) ->page($pageNo, $pageSize)
->order('id desc')
->select()->toArray(); ->select()->toArray();
foreach ($order as &$value){ foreach ($order as &$value){
@ -286,6 +292,9 @@ class StoreOrderLogic extends BaseLogic
*/ */
public function storeOrderCount($storeId, $status, $paid = 1) public function storeOrderCount($storeId, $status, $paid = 1)
{ {
if(empty($storeId)){
return StoreOrder::where(['status' => $status, 'paid' => $paid])->count();
}
return StoreOrder::where(['store_id' => $storeId, 'status' => $status, 'paid' => $paid])->count(); return StoreOrder::where(['store_id' => $storeId, 'status' => $status, 'paid' => $paid])->count();
} }

View File

@ -0,0 +1,32 @@
<?php
namespace app\common\logic\user_product_storage;
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;
class UserProductStorageLogic extends BaseLogic
{
public static function add($order){
$arr=StoreOrderCartInfo::where('oid',$order['id'])->field('product_id,cart_num nums')->select();
if($arr){
$data=$arr;
$data_log=$arr;
foreach ($data as $k=>$v){
$data[$k]['uid']=$order['uid'];
$data[$k]['oid']=$order['id'];
$data[$k]['status']=1;
$data_log[$k]['uid']=$order['uid'];
$data_log[$k]['oid']=$order['id'];
$data_log[$k]['financial_pm']=1;
}
UserProductStorage::insertAll($data);
UserProductStorageLog::insertAll($data_log);
}
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace app\common\logic\user_product_storage_log;
use app\common\logic\BaseLogic;
class UserProductStorageLogLogic extends BaseLogic
{
}

View File

@ -0,0 +1,20 @@
<?php
namespace app\common\model\user_product_storage;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 用户商品储存
* Class UserProductStorage
* @package app\common\model\user_product_storage
*/
class UserProductStorage extends BaseModel
{
use SoftDelete;
protected $name = 'user_product_storage';
protected $deleteTime = 'delete_time';
}

View File

@ -0,0 +1,20 @@
<?php
namespace app\common\model\user_product_storage_log;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 用户商品储存操作日志
* Class UserProductStorageLog
* @package app\common\model\user_product_storage_log
*/
class UserProductStorageLog extends BaseModel
{
use SoftDelete;
protected $name = 'user_product_storage_log';
protected $deleteTime = 'delete_time';
}

View File

@ -2,6 +2,7 @@
namespace app\common\service; namespace app\common\service;
use support\Log;
use Webman\Push\Api; use Webman\Push\Api;
class PushService class PushService
@ -15,6 +16,7 @@ class PushService
*/ */
public static function push($subscription, $uid, $content) public static function push($subscription, $uid, $content)
{ {
Log::info('PushService::push', [$subscription, $uid, $content]);
$api = new Api( $api = new Api(
getenv('PUSH_URL'), getenv('PUSH_URL'),
config('plugin.webman.push.app.app_key'), config('plugin.webman.push.app.app_key'),

View File

@ -75,7 +75,8 @@ class SmsService
return false; return false;
} }
}catch(NoGatewayAvailableException $e){ }catch(NoGatewayAvailableException $e){
throw new BusinessException($e->getMessage());
throw new BusinessException($e->getExceptions());
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\queue\redis;
use app\common\logic\PayNotifyLogic; use app\common\logic\PayNotifyLogic;
use app\common\model\retail\Cashierclass; use app\common\model\retail\Cashierclass;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\user_recharge\UserRecharge;
use app\common\service\pay\PayService; use app\common\service\pay\PayService;
use app\common\service\PushService; use app\common\service\PushService;
use Webman\RedisQueue\Consumer; use Webman\RedisQueue\Consumer;
@ -44,17 +45,29 @@ class CodePaySend implements Consumer
{ {
// 直接更改消息队列数据结构将最大重试次数max_attempts字段设置为0即不再重试。 // 直接更改消息队列数据结构将最大重试次数max_attempts字段设置为0即不再重试。
if($package['attempts'] ==$exception['max_attempts']){ if($package['attempts'] ==$exception['max_attempts']){
$pay = new PayService();
$data = [ $data = [
'order_id' => $package['data']['order_id'], 'order_id' => $package['data']['order_id'],
'paid' => 0, 'paid' => 0,
]; ];
$find=StoreOrder::where($data)->find(); if($package['data']['pay_type']=='recharge'){
if($find){ $order=UserRecharge::where($data)->find();
$order = StoreOrder::update($data);
if($order){ if($order){
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'cash_register','msg'=>'支付超时,订单已被取消,请重新提交订单']); $res=UserRecharge::where($data)->update(['status'=>-1]);
if($res){
PushService::push('wechat_mmp_' . $order['uid'], $order['uid'], ['type'=>'INDUSTRYMEMBERS','msg'=>'支付超时,订单已被取消,请重新提交订单','data'=>['id'=>$data['id'],'paid'=>0]]);
}
}
}else{
$order=StoreOrder::where($data)->find();
if($order){
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'cash_register','msg'=>'支付超时,订单已被取消,请重新提交订单']);
} }
} }
$pay->wechat->close(['out_trade_no'=>$order['order_id']]);
} }
return $package; return $package;
} }

View File

@ -64,6 +64,7 @@ class StoreStorageSend implements Consumer
'batch' => $find['batch'], 'batch' => $find['batch'],
'store_id' => $store_id, 'store_id' => $store_id,
'sales' => 0, 'sales' => 0,
'product_type' => $find['product_type'],
'stock' => 0, 'stock' => 0,
]; ];
$branch = StoreBranchProduct::create($product); $branch = StoreBranchProduct::create($product);

View File

@ -2,7 +2,10 @@
namespace app\statistics\controller; namespace app\statistics\controller;
use app\admin\logic\statistic\TradeStatisticLogic;
use app\common\controller\BaseLikeController; use app\common\controller\BaseLikeController;
use app\common\model\user\User;
use app\common\model\user_recharge\UserRecharge;
use app\statistics\logic\OrderLogic; use app\statistics\logic\OrderLogic;
use app\statistics\logic\ProductLogic; use app\statistics\logic\ProductLogic;
use app\statistics\logic\UserLogic; use app\statistics\logic\UserLogic;
@ -11,25 +14,27 @@ use DateTime;
class IndexController extends BaseLikeController class IndexController extends BaseLikeController
{ {
public $store_id=3; public $store_id = 0;
public function index() public function index()
{ {
$time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$where['paid'] = 1; $where['paid'] = 1;
$res = OrderLogic::dayPayPrice($where); $res = OrderLogic::dayPayPrice($where, $time);
if (OrderLogic::hasError()) { if (OrderLogic::hasError()) {
return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息
} }
return $this->success('ok', ['dayPayPrice' => $res,'title'=>'百合镇农(特)产品交易大数据']); return $this->success('ok', ['dayPayPrice' => $res, 'title' => '百合镇农(特)产品交易大数据']);
} }
public function user() public function user()
{ {
$today = strtotime(date('Y-m-d')); $time = $this->request->get('date', date('Y-m-d'));
$dates=[]; $today = strtotime($time);
$dates = [];
// 循环输出前5天的日期 // 循环输出前5天的日期
for ($i = 0; $i <= 4; $i++) { for ($i = 0; $i <= 4; $i++) {
// 计算前第$i天的日期时间戳 // 计算前第$i天的日期时间戳
@ -37,14 +42,14 @@ class IndexController extends BaseLikeController
// 将时间戳格式化为日期 // 将时间戳格式化为日期
$date = date('Y-m-d', $timestamp); $date = date('Y-m-d', $timestamp);
$dates[]=$date; $dates[] = $date;
} }
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = UserLogic::userCount($where,$dates); $res = UserLogic::userCount($where, $dates);
if (UserLogic::hasError()) { if (UserLogic::hasError()) {
return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息
} }
@ -56,12 +61,13 @@ class IndexController extends BaseLikeController
*/ */
public function product_count() public function product_count()
{ {
$time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = ProductLogic::Count($where); $res = ProductLogic::Count($where, $time);
if (ProductLogic::hasError()) { if (ProductLogic::hasError()) {
return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
} }
@ -72,28 +78,40 @@ class IndexController extends BaseLikeController
*/ */
public function order_user_num_count() public function order_user_num_count()
{ {
$time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = OrderLogic::Count($where); $where['recharge_type']='INDUSTRYMEMBERS';
if (ProductLogic::hasError()) { $where['status']=1;
return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 $where['paid']=1;
} // $res = OrderLogic::Count($where,$time);
return $this->success('ok', $res); // if (ProductLogic::hasError()) {
// return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
// }
$res = UserRecharge::where($where)->whereTime('create_time', $time)->select()->each(function ($item) {
if($item['uid']){
$item['nickname']=User::where('id',$item['uid'])->value('nickname');
}else{
$item['nickname']='';
}
});
return $this->success('ok', $res?->toArray());
} }
/** /**
* 商品销量排行榜统计 * 商品销量排行榜统计
*/ */
public function sales_ranking() public function sales_ranking()
{ {
$time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = ProductLogic::sales($where); $res = OrderLogic::sales($where, $time);
if (ProductLogic::hasError()) { if (ProductLogic::hasError()) {
return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
} }
@ -104,38 +122,31 @@ class IndexController extends BaseLikeController
*/ */
public function user_trade_count() public function user_trade_count()
{ {
$dates = []; $logic = (new TradeStatisticLogic());
$leftToday = $logic->getTopLeftTrade(['create_time' => 'today']);
$leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']);
$totalleft = [$leftToday, $leftyestoday];
foreach ($totalleft as $k => $v) {
$left['name'] = "当日订单金额";
$left['x'] = $v['curve']['x'];
$left['series'][$k]['money'] = round($v['total_money'], 2);
$left['series'][$k]['value'] = array_values($v['curve']['y']);
}
$today = new DateTime(); return $this->data($left);
$thirtyDaysAgo = new DateTime($today->format('Y-m-d'));
$thirtyDaysAgo->modify('-30 days');
for ($i = 0; $i < 31; $i++) {
$date = new DateTime($thirtyDaysAgo->format('Y-m-d'));
$date->modify('+' . $i . ' days');
$dates[] = $date->format('Y-m-d');
}
$store_id = $this->store_id;
$where=[];
if($store_id){
$where['store_id'] = $store_id;
}
$res = UserLogic::TradeCount($where, $dates);
if (UserLogic::hasError()) {
return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息
}
return $this->success('ok', $res);
} }
/** /**
* 当日订单金额 * 当日订单金额
*/ */
public function street_currday_order_count() public function street_currday_order_count()
{ {
$time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = OrderLogic::Currday($where); $res = OrderLogic::Currday($where, $time);
if (ProductLogic::hasError()) { if (ProductLogic::hasError()) {
return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
} }

View File

@ -26,9 +26,8 @@ class OrderLogic extends BaseLogic
]; ];
return $data; return $data;
} }
public static function Currday($where) public static function Currday($where,$date)
{ {
$date = date("Y-m-d");
$startTime = strtotime($date . ' 00:00:00'); // 当天的开始时间戳 $startTime = strtotime($date . ' 00:00:00'); // 当天的开始时间戳
$endTime = strtotime($date . ' 23:59:59'); // 当天的结束时间戳 $endTime = strtotime($date . ' 23:59:59'); // 当天的结束时间戳
@ -57,14 +56,19 @@ class OrderLogic extends BaseLogic
} }
return $data; return $data;
} }
public static function dayPayPrice($where) public static function dayPayPrice($where,$time)
{ {
$todayAmount = UserRecharge::where($where) $todayAmount = UserRecharge::where($where)
->whereDay('create_time') ->whereDay('create_time',$time)
->sum('price'); ->sum('price');
$pay_price = StoreOrder::where($where) $pay_price = StoreOrder::where($where)
->whereDay('create_time') ->whereDay('create_time',$time)
->sum('pay_price'); ->sum('pay_price');
return bcadd($todayAmount, $pay_price, 2); 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

@ -7,22 +7,22 @@ use app\common\model\store_branch_product\StoreBranchProduct;
class ProductLogic extends BaseLogic class ProductLogic extends BaseLogic
{ {
public static function Count($where) public static function Count($where,$time)
{ {
$todayProductCount=StoreBranchProduct::where($where)->count(); $todayProductCount=StoreBranchProduct::where($where)->whereDay('create_time',$time)->count();
$yestertodayProductCount=StoreBranchProduct::where($where)->where('create_time', '<',strtotime(date('Y-md'))-1)->count(); $yestertodayProductCount=StoreBranchProduct::where($where)->where('create_time', '<',strtotime($time)-1)->count();
if ($yestertodayProductCount == 0 ||$todayProductCount==0) { if ($yestertodayProductCount == 0 ||$todayProductCount==0) {
$weeklyProductTotalGrowthRate = 0; $weeklyProductTotalGrowthRate = 0;
} else { } else {
$weeklyProductTotalGrowthRate = ($todayProductCount - $yestertodayProductCount) / $yestertodayProductCount * 100; $weeklyProductTotalGrowthRate =bcdiv(($todayProductCount - $yestertodayProductCount) ,$yestertodayProductCount) * 100;
} }
$todayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time')->count(); $todayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time',$time)->count();
$yestertodayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time', 'yesterday')->count(); $yestertodayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time', date('Y-m-d',strtotime($time)-1))->count();
if ($yestertodayProductCount == 0 ||$todayProductCount==0) { if ($todayNewProductCount == 0 ||$yestertodayNewProductCount==0) {
$weeklyNewProductTotalGrowthRate = 0; $weeklyNewProductTotalGrowthRate = 0;
} else { } else {
$weeklyNewProductTotalGrowthRate = ($todayNewProductCount - $yestertodayNewProductCount) / $yestertodayNewProductCount * 100; $weeklyNewProductTotalGrowthRate =bcdiv(($todayNewProductCount - $yestertodayNewProductCount),$yestertodayNewProductCount) * 100;
} }
$data = [ $data = [
"totalProductCounInfo" => [ "totalProductCounInfo" => [

View File

@ -18,6 +18,7 @@ use app\common\logic\store_order\StoreOrderLogic;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\model\system_store\SystemStoreStaff; use app\common\model\system_store\SystemStoreStaff;
@ -59,9 +60,9 @@ class StoreOrderController extends BaseAdminController
'pay_type' => PayEnum::getPaySceneDesc(), 'pay_type' => PayEnum::getPaySceneDesc(),
'order_status' => [ 'order_status' => [
'wait_send' => $orderLogic->storeOrderCount($this->request->adminInfo['store_id'], 0), 'wait_send' => $orderLogic->storeOrderCount($this->request->adminInfo['store_id'], 0),
'to_be_paid' => $orderLogic->storeOrderCount($this->request->adminInfo['store_id'], 0, 0), 'to_be_paid' => $orderLogic->storeOrderCount(0, 0, 0),
'wait_receive' => $orderLogic->storeOrderCount($this->request->adminInfo['store_id'], 1), 'wait_receive' => $orderLogic->storeOrderCount(0, 1),
'finish' => $orderLogic->storeOrderCount($this->request->adminInfo['store_id'], 2), 'finish' => $orderLogic->storeOrderCount(0, 2),
], ],
]); ]);
} }
@ -85,13 +86,13 @@ class StoreOrderController extends BaseAdminController
$params = $this->request->post(); $params = $this->request->post();
$params['store_id'] = $this->adminInfo['store_id']; $params['store_id'] = $this->adminInfo['store_id'];
$user = User::where('id', $params['uid'])->find(); $user = User::where('id', $params['uid'])->find();
$res = StoreOrderLogic::cartIdByOrderInfo($cartId, null, $user, $params); $res = OrderLogic::cartIdByOrderInfo($cartId, null, $user, $params);
if ($res == false) { if ($res == false) {
$msg = StoreOrderLogic::getError(); $msg = OrderLogic::getError();
if ($msg == '购物车为空') { if ($msg == '购物车为空') {
return $this->data([]); return $this->data([]);
} }
return $this->fail(StoreOrderLogic::getError()); return $this->fail(OrderLogic::getError());
} }
return $this->data($res); return $this->data($res);
} }
@ -105,9 +106,9 @@ class StoreOrderController extends BaseAdminController
if (empty($user)) { if (empty($user)) {
return $this->fail('无该用户请检查'); return $this->fail('无该用户请检查');
} }
$order = StoreOrderLogic::cartIdByOrderInfo($params['cart_id'], null, $user, $params); $order = OrderLogic::cartIdByOrderInfo($params['cart_id'], null, $user, $params);
if (!$order) { if (!$order) {
return $this->fail(StoreOrderLogic::getError()); return $this->fail(OrderLogic::getError());
} }
if ($params['type'] == 1) { if ($params['type'] == 1) {
if ($order['order']['pay_price'] > $user['purchase_funds']) { if ($order['order']['pay_price'] > $user['purchase_funds']) {
@ -169,7 +170,8 @@ class StoreOrderController extends BaseAdminController
$user = User::where('id', $uid)->find(); $user = User::where('id', $uid)->find();
} }
$params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id用于判断是否是当前店铺的订单 $params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id用于判断是否是当前店铺的订单
$order = StoreOrderLogic::createOrder($cartId, $addressId, $user, $params); $params['shipping_type'] =3;
$order = OrderLogic::createOrder($cartId, $addressId, $user, $params);
if ($order != false) { if ($order != false) {
switch ($pay_type) { switch ($pay_type) {
case PayEnum::PURCHASE_FUNDS: case PayEnum::PURCHASE_FUNDS:
@ -320,15 +322,11 @@ class StoreOrderController extends BaseAdminController
// ] // ]
public function writeoff_list(StoreOrderLogic $orderLogic) public function writeoff_list(StoreOrderLogic $orderLogic)
{ {
$page_no = (int)$this->request->post('page_no', 1); $page_no = (int)$this->request->get('page_no', 1);
$page_size = (int)$this->request->post('page_size', 15); $page_size = (int)$this->request->get('page_size', 15);
$params = $this->request->post(); $params = $this->request->get();
$params['page_no'] = $page_no; $params['page_no'] = $page_no;
$params['page_size'] = $page_size; $params['page_size'] = $page_size;
if (empty($page_no) || empty($page_size)) {
$params['page_no'] = 1;
$params['page_size'] = 15;
}
$params['store_id'] = $this->request->adminInfo['store_id']; $params['store_id'] = $this->request->adminInfo['store_id'];
$result = $orderLogic->writeList($params); $result = $orderLogic->writeList($params);
@ -436,7 +434,7 @@ class StoreOrderController extends BaseAdminController
$find['nickname'] = $user['nickname'] ?? ''; $find['nickname'] = $user['nickname'] ?? '';
$find['user_mobile'] = $user['mobile'] ?? ''; $find['user_mobile'] = $user['mobile'] ?? '';
$find['info'] = StoreOrderCartInfo::where('oid', $find['id'])->field('store_id,product_id,cart_num,cart_info')->select()->each(function ($item) { $find['info'] = StoreOrderCartInfo::where('oid', $find['id'])->field('store_id,product_id,cart_num,cart_info')->select()->each(function ($item) {
$goods = StoreBranchProduct::where(['store_id' => $item['store_id'], 'product_id' => $item['product_id']])->field('store_name,unit')->find(); $goods = StoreProduct::where(['id' => $item['product_id']])->field('store_name,unit')->find();
$item['unit_name'] = StoreProductUnit::where('id', $goods['unit'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $goods['unit'])->value('name');
$item['store_name'] = $goods['store_name']; $item['store_name'] = $goods['store_name'];
$item['total_price'] = $item['cart_info']['total_price']; $item['total_price'] = $item['cart_info']['total_price'];

View File

@ -19,31 +19,9 @@ use app\store\validate\store_product\StoreProductValidate;
// #[ApiDoc\title('商品列表')] // #[ApiDoc\title('商品列表')]
class StoreProductController extends BaseAdminController class StoreProductController extends BaseAdminController
{ {
/**
// #[ * 商品列表
// ApiDoc\Title('商品列表'), */
// ApiDoc\url('/store/store_product/storeProduct/lists'),
// ApiDoc\Method('GET'),
// ApiDoc\NotHeaders(),
// ApiDoc\Query(name: 'cate_id', type: 'int', require: false, desc: '分类id'),
// ApiDoc\Query(name: 'store_name', type: 'string', require: false, desc: '商品名称'),
// ApiDoc\Query(name: 'status', type: 'int', require: false, desc: '状态1上架2下架3售罄4库存告警'),
// ApiDoc\Header(ref: [Definitions::class, "token"]),
// ApiDoc\Query(ref: [Definitions::class, "page"]),
// ApiDoc\ResponseSuccess("data", type: "array", children: [
// ['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
// ['name' => 'product_id', 'desc' => '商品ID', 'type' => 'int'],
// ['name' => 'image', 'desc' => '图片', 'type' => 'string'],
// ['name' => 'store_name', 'desc' => '商品名称', 'type' => 'string'],
// ['name' => 'price', 'desc' => '零售价', 'type' => 'float'],
// ['name' => 'cost', 'desc' => '成本价', 'type' => 'float'],
// ['name' => 'sales', 'desc' => '销量', 'type' => 'int'],
// ['name' => 'stock', 'desc' => '库存', 'type' => 'int'],
// ['name' => 'unit_name', 'desc' => '单位', 'type' => 'string'],
// ['name' => 'cate_name', 'desc' => '分类', 'type' => 'string'],
// ['name' => 'status', 'desc' => '状态1上架0下架', 'type' => 'string'],
// ]),
// ]
public function lists() public function lists()
{ {
return $this->dataLists(new StoreBranchProductLists()); return $this->dataLists(new StoreBranchProductLists());
@ -194,5 +172,4 @@ class StoreProductController extends BaseAdminController
StoreBranchProductLogic::stock($params); StoreBranchProductLogic::stock($params);
return $this->success('操作成功', [], 1, 1); return $this->success('操作成功', [], 1, 1);
} }
} }

View File

@ -4,11 +4,13 @@
namespace app\store\controller\user; namespace app\store\controller\user;
use app\common\service\SmsService;
use app\store\controller\BaseAdminController; use app\store\controller\BaseAdminController;
use app\store\lists\user\UserLists; use app\store\lists\user\UserLists;
use app\admin\logic\user\UserLogic; use app\admin\logic\user\UserLogic;
use app\admin\validate\user\UserValidate; use app\admin\validate\user\UserValidate;
use app\common\model\user\User; use app\common\model\user\User;
use support\Cache;
class UserController extends BaseAdminController class UserController extends BaseAdminController
{ {
@ -18,10 +20,36 @@ class UserController extends BaseAdminController
return $this->dataLists(new UserLists()); return $this->dataLists(new UserLists());
} }
/**
* 用户档案短信
* @return \support\Response
*/
public function archives_sms()
{
$mobile = $this->request->post('mobile','');
if (empty($mobile))
return $this->fail('手机号缺失');
$res = (new \app\api\logic\user\UserLogic())->dealReportingSms($mobile,'_userArchives');
if ($res){
return $this->success('发送成功');
}
return $this->fail('发送失败');
}
public function add() public function add()
{ {
$params = (new UserValidate())->post()->goCheck('storeAdd'); $params = (new UserValidate())->post()->goCheck('storeAdd');
$code = $params['code'];
if($code && $params['mobile']){
$remark = $params['mobile'].'_userArchives';
$codeCache = Cache::get($remark);
if(empty($codeCache)){
return $this->fail('验证码不存在');
}
if ($codeCache != $code) {
return $this->fail('验证码错误');
}
}
UserLogic::StoreAdd($params); UserLogic::StoreAdd($params);
if (UserLogic::hasError() ) { if (UserLogic::hasError() ) {
return $this->fail(UserLogic::getError()); return $this->fail(UserLogic::getError());

View File

@ -6,10 +6,12 @@ namespace app\store\lists\cart;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\order\Cart; use app\common\model\order\Cart;
use app\common\lists\ListsExtendInterface; use app\common\model\Config;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\user\User;
use app\common\lists\ListsExtendInterface;
/** /**
* 购物车列表 * 购物车列表
@ -18,10 +20,9 @@ use app\common\model\store_product_unit\StoreProductUnit;
*/ */
class CartList extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface class CartList extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
{ {
protected $total_price = 0; protected $total_price = 0;
protected $activity_price = 0;
protected $off_activity = 0;
/** /**
* @notes 设置搜索条件 * @notes 设置搜索条件
* @return \string[][] * @return \string[][]
@ -31,8 +32,6 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
{ {
return []; return [];
} }
/** /**
* @notes 购物车列表 * @notes 购物车列表
* @return array * @return array
@ -43,27 +42,42 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
*/ */
public function lists($where = []): array public function lists($where = []): array
{ {
$this->searchWhere[]=['staff_id','=',$this->adminId]; $userId = $this->request->get('uid');
$this->searchWhere[]=['is_pay','=',0]; $where = [
$list = Cart::where($this->searchWhere) 'staff_id' => $this->adminId,
->field('id,product_id,cart_num,store_id') 'is_pay' => 0
];
$list = Cart::where($this->searchWhere)->where($where)
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) { ->select()->each(function ($item) {
$find = StoreBranchProduct::where(['product_id' => $item['product_id'],'store_id'=>$item['store_id']])
->field('product_id,image,price,store_name,unit')
->find();
if ($find) {
$item['total_price'] = bcmul($item['cart_num'], $find['price'], 2);
$item['image'] = $find['image'];
$item['price'] = $find['price'];
$item['store_name'] = $find['store_name'];
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
}
return $item; return $item;
}) })
->toArray(); ->toArray();
$off_activity = Config::where('name', 'off_activity')->value('value');
$this->off_activity = $off_activity;
foreach ($list as $key => &$item) {
$find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']])
->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price')
->withTrashed()
->find();
if ($find) {
if($off_activity==1){
$this->activity_price = bcadd(bcmul($find['cost'],$item['cart_num'], 2), $this->activity_price, 2);
$item['price'] = $find['cost'];
}else{
$item['price'] = $find['price'];
}
$item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2);
$this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2);
$item['image'] = $find['image'];
$item['cost'] = $find['cost'];
$item['store_name'] = $find['store_name'];
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
}
}
return $list; return $list;
} }
@ -75,11 +89,30 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
*/ */
public function count(): int public function count(): int
{ {
return Cart::where($this->searchWhere)->count(); $userId = $this->request->userId;
if (!$userId) return 0;
$where = [
'uid' => $userId,
'is_pay' => 0
];
return Cart::where($this->searchWhere)->where($where)->count();
} }
public function extend() public function extend()
{ {
// return ['total_price' => $this->total_price]; $data = [
'off_activity' => $this->off_activity,
'total_price' => $this->total_price,
'msg' => '',
'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['pay_price'] = $this->activity_price;
}
}
return $data;
} }
} }

View File

@ -54,8 +54,24 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
} elseif ($is_sashier == 2) { //小程序订单 } elseif ($is_sashier == 2) { //小程序订单
$this->searchWhere[] = ['pay_type', 'in', [7, 3, 18,19]]; $this->searchWhere[] = ['pay_type', 'in', [7, 3, 18,19]];
} }
return StoreOrder::where($this->searchWhere) $status = $this->request->get('status','');
->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status', 'paid', 'total_num']) switch ($status){
case -1:
$this->searchWhere[] = ['status', '=', 0];
$this->searchWhere[] = ['paid', '=', 0];
break;
case 1:
$this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[] = ['paid', '=', 1];
break;
case 2:
$this->searchWhere[] = ['status', '=', 2];
$this->searchWhere[] = ['paid', '=', 1];
break;
}
return StoreOrder::where($this->searchWhere)->with(['user'])
->field(['id', 'order_id', 'pay_price', 'pay_time','uid', 'pay_type', 'status', 'paid', 'total_num'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) use ($store_id) { ->select()->each(function ($item) use ($store_id) {

View File

@ -5,6 +5,7 @@ namespace app\store\lists\user;
use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\user_sign\UserSign;
use app\store\lists\BaseAdminDataLists; use app\store\lists\BaseAdminDataLists;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\user\UserShip; use app\common\model\user\UserShip;
@ -50,6 +51,8 @@ class UserLists extends BaseAdminDataLists implements ListsSearchInterface
$data['return_money'] = StoreFinanceFlow:: $data['return_money'] = StoreFinanceFlow::
where(['user_id'=>$data['id'],'status'=>0,'financial_pm'=>0]) where(['user_id'=>$data['id'],'status'=>0,'financial_pm'=>0])
->sum('number'); ->sum('number');
$data['amount_frozen'] = UserSign::where('uid',$data['id'])->where('status',0)->sum('number');
$data['get_frozen'] = UserSign::where('uid',$data['id'])->where('status',1)->sum('number');
})->toArray(); })->toArray();
return $lists; return $lists;

View File

@ -36,6 +36,7 @@ use app\common\model\user_recharge\UserRecharge;
use app\common\service\ConfigService; use app\common\service\ConfigService;
use app\common\service\FileService; use app\common\service\FileService;
use app\statistics\logic\OrderLogic; use app\statistics\logic\OrderLogic;
use app\statistics\logic\OrderLogic;
/** /**
@ -84,7 +85,7 @@ class WorkbenchLogic extends BaseLogic
$data['income_amount'] = StoreFinanceFlow::where($storeFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number'); $data['income_amount'] = StoreFinanceFlow::where($storeFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number');
//门店收款金额 //门店收款金额
$all_where['paid'] = 1; $all_where['paid'] = 1;
$data['receipt_amount'] = OrderLogic::dayPayPrice($all_where); $data['receipt_amount'] = OrderLogic::dayPayPrice($all_where,date('Y-m-d',time()));
// $data['receipt_amount'] = UserRecharge::where($userRechargeWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('price'); // $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['deposit_amount'] = StoreFinanceFlow::where($storeFinanceWhereTwo)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number');