# Conflicts:
#	app/common/logic/store_order/StoreOrderLogic.php
This commit is contained in:
luofei 2024-06-08 16:53:43 +08:00
commit 50e415ae2d
12 changed files with 201 additions and 155 deletions

View File

@ -29,7 +29,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
{ {
return [ return [
'=' => ['product_id', 'cate_id','store_id'], '=' => ['product_id', 'cate_id','store_id'],
'%like%' => ['store_name|bar_code'], '%pipe_like%' => ['store_name_code'=>'store_name|bar_code'],
]; ];
} }
@ -63,7 +63,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
} }
}) })
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc', 'id' => 'desc']) ->order(['sort' => 'desc','stock'=>'desc','id' => 'desc'])
->select() ->select()
->each(function ($item) { ->each(function ($item) {
$item['system_store_name']=SystemStore::where('id',$item['store_id'])->value('name'); $item['system_store_name']=SystemStore::where('id',$item['store_id'])->value('name');

View File

@ -138,7 +138,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface
$check = DictType::where('type','activities')->find(); $check = DictType::where('type','activities')->find();
foreach ($data as &$value){ foreach ($data as &$value){
if(isset($check) && $check['status'] == 1){ if(isset($check) && $check['status'] == 1){
$value['price'] = StoreProduct::where('product_id',$value['product_id'])->value('ot_price'); $value['price'] = StoreProduct::where('id',$value['product_id'])->value('ot_price');
} }
$value['is_default'] = 0; $value['is_default'] = 0;
if($store_id == 2){ if($store_id == 2){

View File

@ -39,6 +39,8 @@ use Yansongda\Pay\Event\PayEnd;
class OrderLogic extends BaseLogic class OrderLogic extends BaseLogic
{ {
public static $total; public static $total;
public static $cost;
public static $profit;
/** /**
* @notes 获取购物车商品信息 * @notes 获取购物车商品信息
@ -56,6 +58,9 @@ class OrderLogic extends BaseLogic
} }
try { try {
self::$total = 0; self::$total = 0;
self::$cost = 0;//成本
self::$profit = 0;//利润
/** 计算价格 */ /** 计算价格 */
$check = DictType::where('type', 'activities')->find(); $check = DictType::where('type', 'activities')->find();
foreach ($cart_select as $k => $v) { foreach ($cart_select as $k => $v) {
@ -63,9 +68,14 @@ class OrderLogic extends BaseLogic
if (!$find) { if (!$find) {
continue; continue;
} }
$productBase = StoreProduct::where('id', $find['product_id'])->withTrashed()->field('price,ot_price,cost')->find();
if (isset($check) && $check['status'] == 1) { if (isset($check) && $check['status'] == 1) {
$find['price'] = StoreProduct::where('product_id',$find['product_id'])->value('ot_price'); $find['price'] = $productBase['ot_price'];
} }
//利润
$onePrice = bcsub($productBase['price'], $productBase['ot_price'], 2);
$cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2);//利润
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $productBase['cost'], 2) ?? 0;
$cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱 $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱
$cart_select[$k]['price'] = $find['price']; $cart_select[$k]['price'] = $find['price'];
$cart_select[$k]['product_id'] = $v['goods']; $cart_select[$k]['product_id'] = $v['goods'];
@ -87,6 +97,8 @@ class OrderLogic extends BaseLogic
$cart_select[$k]['imgs'] = $find['image']; $cart_select[$k]['imgs'] = $find['image'];
$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 = bcadd(self::$total, $cart_select[$k]['total'], 2); self::$total = bcadd(self::$total, $cart_select[$k]['total'], 2);
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2);
self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
} }
//TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级 //TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级
$pay_price = self::$total; $pay_price = self::$total;
@ -94,8 +106,9 @@ class OrderLogic extends BaseLogic
$vipPrice = 0; $vipPrice = 0;
if (isset($check) && $check['status'] == 1) { if (isset($check) && $check['status'] == 1) {
// $discountRate = '0.99';//首单逻辑 // $discountRate = '0.99';//首单逻辑
$discountRate = $check['remark']; // $pay_price 是价格
$discountRate = bcdiv($discountRate, '100', 2); $discountRate = $check['remark'];//折扣
$discountRate = bcdiv($discountRate, '10', 2);
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
} else { } else {
$userVip = User::where('id', \request()->userId)->value('user_ship'); $userVip = User::where('id', \request()->userId)->value('user_ship');
@ -127,10 +140,14 @@ class OrderLogic extends BaseLogic
bcscale(2); bcscale(2);
$vipPrice = bcsub(self::$total, $pay_price, 2); $vipPrice = bcsub(self::$total, $pay_price, 2);
} }
//成本价 收益
$order = [ $order = [
'create_time' => time(), 'create_time' => time(),
'order_id' => getNewOrderId('PF'), 'order_id' => getNewOrderId('PF'),
'total_price' => self::$total,//总价 'total_price' => self::$total,//总价
'cost' => self::$cost,//成本价
'profit' => self::$profit,//利润
'pay_price' => $pay_price,//后期可能有降价抵扣 'pay_price' => $pay_price,//后期可能有降价抵扣
'vip_price' => $vipPrice, 'vip_price' => $vipPrice,
'total_num' => count($cart_select),//总数 'total_num' => count($cart_select),//总数
@ -140,6 +157,10 @@ class OrderLogic extends BaseLogic
'store_id' => $params['store_id'] ?? 0, 'store_id' => $params['store_id'] ?? 0,
'shipping_type' => $params['shipping_type'] ?? 1//配送方式 1=快递 2=门店自提 'shipping_type' => $params['shipping_type'] ?? 1//配送方式 1=快递 2=门店自提
]; ];
$order['default_delivery'] = 0;
if($params['store_id']){
$order['default_delivery'] = SystemStore::where('id',$params['store_id'])->value('default_delivery');
}
} catch (\Exception $e) { } catch (\Exception $e) {
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
@ -167,6 +188,7 @@ class OrderLogic extends BaseLogic
$_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;
if (isset($params['reservation_time'])) { if (isset($params['reservation_time'])) {
$_order['reservation_time'] = $params['reservation_time']; $_order['reservation_time'] = $params['reservation_time'];
$_order['reservation'] = YesNoEnum::YES; $_order['reservation'] = YesNoEnum::YES;
@ -617,11 +639,13 @@ class OrderLogic extends BaseLogic
//todo 单子不是完成的不允许退款 //todo 单子不是完成的不允许退款
//单笔不拆单子直接修改状态 //单笔不拆单子直接修改状态
$order = StoreOrder::where('id', $params['id'])->withTrashed()->findOrEmpty(); $order = StoreOrder::where('id', $params['id'])->withTrashed()->findOrEmpty();
$params['refund_num'] = 1;//todo 拿实际数量
if (count($params['old_cart_id']) == 1) { if (count($params['old_cart_id']) == 1) {
$order->refund_status = OrderEnum::REFUND_STATUS_YES; $order->refund_status = OrderEnum::REFUND_STATUS_YES;
$order->status = OrderEnum::ALREADY_REFUND; $order->status = OrderEnum::ALREADY_REFUND;
$order->refund_reason_wap_explain = $params['refund_message'] ?? ''; $order->refund_reason_wap_explain = $params['refund_message'] ?? '';
$order->refund_num = $params['refund_num']; $order->mark = $params['mark'] ?? '';
$order->refund_num = $params['refund_num'] ?? 1;
$refund_price_cart = StoreOrderCartInfo::where('oid', $params['id']) $refund_price_cart = StoreOrderCartInfo::where('oid', $params['id'])
->field('id,oid,cart_info') ->field('id,oid,cart_info')
->find()->toArray(); ->find()->toArray();
@ -684,7 +708,6 @@ class OrderLogic extends BaseLogic
} }
public static function dealCreateLeftOrder($order, $cart_info, $params) public static function dealCreateLeftOrder($order, $cart_info, $params)
{ {
//查出不在这个退货中的数据 //查出不在这个退货中的数据
@ -725,7 +748,6 @@ class OrderLogic extends BaseLogic
} }
public static function dealCreateRefundOrder($order, $params) public static function dealCreateRefundOrder($order, $params)
{ {
$order['order_id'] = $order['order_id'] . '-1'; $order['order_id'] = $order['order_id'] . '-1';
@ -737,6 +759,7 @@ class OrderLogic extends BaseLogic
$order['status'] = OrderEnum::ALREADY_REFUND; $order['status'] = OrderEnum::ALREADY_REFUND;
$order['refund_num'] = $params['refund_num'];//按数量整单退剩余的 $order['refund_num'] = $params['refund_num'];//按数量整单退剩余的
$order['refund_reason_wap_explain'] = $params['refund_message'] ?? ''; $order['refund_reason_wap_explain'] = $params['refund_message'] ?? '';
$order['mark'] = $params['mark'] ?? '';
$order['total_num'] = count($params['old_cart_id']); $order['total_num'] = count($params['old_cart_id']);
$refund_price_cart = StoreOrderCartInfo::whereIn('old_cart_id', $params['old_cart_id']) $refund_price_cart = StoreOrderCartInfo::whereIn('old_cart_id', $params['old_cart_id'])
->field('id,oid,cart_info') ->field('id,oid,cart_info')

View File

@ -30,6 +30,7 @@
}else{ }else{
StoreVisit::create([ StoreVisit::create([
'uid' => $uid, 'uid' => $uid,
'store_id' => $params['store_id']??0,
'product_id' => $params['product_id'], 'product_id' => $params['product_id'],
'cate_id' => $params['cate_id'], 'cate_id' => $params['cate_id'],
'count' => 1, 'count' => 1,

View File

@ -19,7 +19,7 @@ class OrderValidate extends BaseValidate
protected $rule = [ protected $rule = [
'verify_code' => 'require', 'verify_code' => 'require',
'refund_message' => 'require', 'refund_message' => 'require',
'refund_num' => 'require|number', // 'refund_num' => 'require|number',
'id' => 'require|number', 'id' => 'require|number',
'old_cart_id' => 'require|array', 'old_cart_id' => 'require|array',
'refund_type' => 'require|number', 'refund_type' => 'require|number',
@ -33,7 +33,7 @@ class OrderValidate extends BaseValidate
protected $field = [ protected $field = [
'verify_code' => '验证码', 'verify_code' => '验证码',
'refund_message' => '退款原因', 'refund_message' => '退款原因',
'refund_num' => '退款数量', // 'refund_num' => '退款数量',
'id' => '订单id', 'id' => '订单id',
'old_cart_id' => '购物车id', 'old_cart_id' => '购物车id',
'refund_type' => '退款申请类型', 'refund_type' => '退款申请类型',
@ -57,7 +57,7 @@ class OrderValidate extends BaseValidate
*/ */
public function sceneAdd() public function sceneAdd()
{ {
return $this->only(['refund_message','refund_num','id','old_cart_id','refund_type']); return $this->only(['refund_message','id','old_cart_id','refund_type']);
} }

View File

@ -18,6 +18,7 @@ class OrderEnum
* @SUPPLIER_ORDER_OBTAINS 供应链订单获得 * @SUPPLIER_ORDER_OBTAINS 供应链订单获得
* @PLATFORM_ORDER_PAY 平台订单支付 * @PLATFORM_ORDER_PAY 平台订单支付
* @SYSTEM_SET 系统设置 * @SYSTEM_SET 系统设置
* @OWN_GET 平台收入
*/ */
const USER_ORDER_PAY = 1; const USER_ORDER_PAY = 1;
const MERCHANT_ORDER_OBTAINS = 2; const MERCHANT_ORDER_OBTAINS = 2;
@ -30,6 +31,8 @@ class OrderEnum
const CASHIER_ORDER_PAY = 9; const CASHIER_ORDER_PAY = 9;
const CASHIER_CASH_ORDER_PAY = 10; const CASHIER_CASH_ORDER_PAY = 10;
const OWN_GET = 3;
/** /**
* 收入支出类型 * 收入支出类型

View File

@ -38,7 +38,6 @@ trait ListsSearchTrait
$class_value = $this->request->__get('class_value'); // 获取class_value的值 $class_value = $this->request->__get('class_value'); // 获取class_value的值
if ($class_value !== null) { if ($class_value !== null) {
$this->params = array_merge($this->params, $class_value); $this->params = array_merge($this->params, $class_value);
} }
foreach ($search as $whereType => $whereFields) { foreach ($search as $whereType => $whereFields) {
switch ($whereType) { switch ($whereType) {
@ -57,6 +56,15 @@ trait ListsSearchTrait
$where[] = [$whereField, $whereType, $this->params[$paramsName]]; $where[] = [$whereField, $whereType, $this->params[$paramsName]];
} }
break; break;
case '%pipe_like%':
foreach ($whereFields as $k=>$whereField) {
$paramsName = substr_symbol_behind($whereField);
if (!isset($this->params[$k]) || empty($this->params[$k])) {
continue;
}
$where[] = [$whereField, 'like', '%' . $this->params[$k] . '%'];
}
break;
case '%like%': case '%like%':
foreach ($whereFields as $whereField) { foreach ($whereFields as $whereField) {
$paramsName = substr_symbol_behind($whereField); $paramsName = substr_symbol_behind($whereField);

View File

@ -233,13 +233,6 @@ class StoreOrderLogic extends BaseLogic
'total' => $total, 'total' => $total,
'currency' => 'CNY', 'currency' => 'CNY',
], ],
// '_action' => 'jsapi', // jsapi 退款,默认
// '_action' => 'app', // app 退款
// '_action' => 'combine', // 合单退款
// '_action' => 'h5', // h5 退款
// '_action' => 'miniapp', // 小程序退款
// '_action' => 'native', // native 退款
]; ];
$res = $wechat->wechat->refund($order); $res = $wechat->wechat->refund($order);

View File

@ -2,7 +2,8 @@
namespace app\store\controller\store_order; namespace app\store\controller\store_order;
use app\api\logic\order\OrderLogic;
use app\api\validate\OrderValidate;
use app\store\lists\store_order\StoreOrderLists; use app\store\lists\store_order\StoreOrderLists;
use app\common\controller\Definitions; use app\common\controller\Definitions;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
@ -11,6 +12,7 @@ use app\common\logic\PayNotifyLogic;
use app\common\logic\SystemStoreStaffLogic; use app\common\logic\SystemStoreStaffLogic;
use app\store\controller\BaseAdminController; use app\store\controller\BaseAdminController;
use app\common\logic\store_order\StoreOrderLogic; use app\common\logic\store_order\StoreOrderLogic;
use app\common\model\store_order\StoreOrder;
use app\store\validate\store_order\StoreOrderValidate; use app\store\validate\store_order\StoreOrderValidate;
use hg\apidoc\annotation as ApiDoc; use hg\apidoc\annotation as ApiDoc;
use Webman\RedisQueue\Redis; use Webman\RedisQueue\Redis;
@ -173,4 +175,18 @@ class StoreOrderController extends BaseAdminController
return $this->fail(StoreOrderLogic::getError()); return $this->fail(StoreOrderLogic::getError());
} }
} }
public function writeoff_order()
{
$params = (new OrderValidate())->post()->goCheck('check');
$count = StoreOrder::where('verify_code',$params['verify_code'])->count();
if(empty($count)){
return $this->fail('无该核销码请检查');
}
$res = OrderLogic::writeOff($params);
if ($res) {
return $this->success('核销成功');
}
return $this->fail('核销失败'.OrderLogic::getError());
}
} }

View File

@ -43,8 +43,8 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
*/ */
public function lists($where = []): array public function lists($where = []): array
{ {
$this->searchWhere[]=['staff_id'=>$this->adminId]; $this->searchWhere[]=['staff_id','=',$this->adminId];
$this->searchWhere[]=['is_pay'=>0]; $this->searchWhere[]=['is_pay','=',0];
$list = Cart::where($this->searchWhere) $list = Cart::where($this->searchWhere)
->field('id,product_id,cart_num,store_id') ->field('id,product_id,cart_num,store_id')
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)

View File

@ -27,7 +27,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['pay_type'], '=' => ['pay_type','paid'],
'%like%' => ['order_id'], '%like%' => ['order_id'],
'between_time' => 'create_time', 'between_time' => 'create_time',
]; ];
@ -54,14 +54,16 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
$this->searchWhere[] = ['pay_type','=',7]; $this->searchWhere[] = ['pay_type','=',7];
} }
return StoreOrder::where($this->searchWhere) return StoreOrder::where($this->searchWhere)
->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status']) ->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status','paid'])
->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) {
$item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : ''; $item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : '';
$item['status_name'] = OrderEnum::getOrderType($item['status']) ?? ''; $item['status_name'] = OrderEnum::getOrderType($item['status']) ?? '';
if ($item['paid'] == 0) { if ($item['paid'] == 0) {
$item['status_name'] = '待支付'; $item['paid_name'] = '待支付';
}else{
$item['paid_name'] = '已支付';
} }
$product_id = StoreOrderCartInfo::where('oid', $item['id'])->limit(3)->column('product_id'); $product_id = StoreOrderCartInfo::where('oid', $item['id'])->limit(3)->column('product_id');
if ($product_id) { if ($product_id) {

View File

@ -28,7 +28,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['store_name', 'cate_id', 'store_id'], '=' => ['cate_id', 'store_id']
]; ];
} }