库存减少和创建扫码优化
This commit is contained in:
parent
3d55b3f505
commit
c0ee92c932
@ -26,6 +26,7 @@ use app\common\model\user\UserShip;
|
|||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
use taoser\exception\ValidateException;
|
use taoser\exception\ValidateException;
|
||||||
|
use think\db\Raw;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use Workerman\Events\Select;
|
use Workerman\Events\Select;
|
||||||
@ -68,7 +69,7 @@ class OrderLogic extends BaseLogic
|
|||||||
/** 计算价格 */
|
/** 计算价格 */
|
||||||
$check = DictType::where('type', 'activities')->find();
|
$check = DictType::where('type', 'activities')->find();
|
||||||
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('store_name,image,unit,price,cost,product_id')->find();
|
$find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field('id branch_product_id,store_name,image,unit,price,cost,product_id')->find();
|
||||||
if (!$find) {
|
if (!$find) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -104,6 +105,7 @@ class OrderLogic extends BaseLogic
|
|||||||
// }
|
// }
|
||||||
$cartInfo['vip_price'] = 0; //$cart_select[$k]['total'] - $vipPrice ?? 0;
|
$cartInfo['vip_price'] = 0; //$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]['name'] = $find['store_name'];
|
$cart_select[$k]['name'] = $find['store_name'];
|
||||||
$cart_select[$k]['imgs'] = $find['image'];
|
$cart_select[$k]['imgs'] = $find['image'];
|
||||||
@ -158,9 +160,9 @@ class OrderLogic extends BaseLogic
|
|||||||
//成本价 收益
|
//成本价 收益
|
||||||
$order = [
|
$order = [
|
||||||
'create_time' => time(),
|
'create_time' => time(),
|
||||||
'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' => self::$profit, //利润
|
'profit' => self::$profit, //利润
|
||||||
'pay_price' => $pay_price, //后期可能有降价抵扣
|
'pay_price' => $pay_price, //后期可能有降价抵扣
|
||||||
'vip_price' => $vipPrice,
|
'vip_price' => $vipPrice,
|
||||||
@ -193,7 +195,10 @@ class OrderLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
static public function createOrder($cartId, $addressId, $user = null, $params = [])
|
static public function createOrder($cartId, $addressId, $user = null, $params = [])
|
||||||
{
|
{
|
||||||
$verify_code = verificationCode();
|
$order_id = getNewOrderId('PF');
|
||||||
|
$code = rand(1,10).'-'.substr($order_id, -5);
|
||||||
|
$verify_code = createCode($code);
|
||||||
|
$params['order_id'] = $order_id;
|
||||||
$params['verify_code'] =$verify_code;
|
$params['verify_code'] =$verify_code;
|
||||||
$orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params);
|
$orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params);
|
||||||
if (!$orderInfo) {
|
if (!$orderInfo) {
|
||||||
@ -227,13 +232,21 @@ class OrderLogic extends BaseLogic
|
|||||||
try {
|
try {
|
||||||
$order = StoreOrder::create($_order);
|
$order = StoreOrder::create($_order);
|
||||||
$goods_list = $orderInfo['cart_list'];
|
$goods_list = $orderInfo['cart_list'];
|
||||||
|
$updateData = [];
|
||||||
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'] = request()->userId;
|
$goods_list[$k]['uid'] = request()->userId;
|
||||||
$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
|
||||||
|
$stock = StoreBranchProduct::where('id',$v['branch_product_id'])->value('stock');
|
||||||
|
$updateData[] = [
|
||||||
|
'id' => $v['branch_product_id'],
|
||||||
|
'stock' => $stock-$v['cart_num'],
|
||||||
|
'sales' => ['inc', $v['cart_num']]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
(new StoreOrderCartInfo())->saveAll($goods_list);
|
(new StoreOrderCartInfo())->saveAll($goods_list);
|
||||||
|
(new StoreBranchProduct())->saveAll($updateData);
|
||||||
$where = ['is_pay' => 0];
|
$where = ['is_pay' => 0];
|
||||||
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
|
@ -375,6 +375,16 @@ if (!function_exists('verificationCode')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('createCode')) {
|
||||||
|
function createCode($code) {
|
||||||
|
$check = \app\common\model\store_order\StoreOrder::where('verify_code',$code)->count();
|
||||||
|
if($check){
|
||||||
|
$orderPickupCode = rand(1,10).'-'.str_pad(rand(0, 99999), 5, '0', STR_PAD_LEFT);
|
||||||
|
return createCode($orderPickupCode);
|
||||||
|
}
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!function_exists('haversineDistance')) {
|
if (!function_exists('haversineDistance')) {
|
||||||
function haversineDistance($latitude1, $longitude1, $latitude2, $longitude2) {
|
function haversineDistance($latitude1, $longitude1, $latitude2, $longitude2) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user