更新秒杀

This commit is contained in:
zoomtk@126.com 2023-05-23 08:47:04 +08:00
parent bab6ea2b6f
commit b6730cdef8
12 changed files with 432 additions and 411 deletions

View File

@ -11,7 +11,7 @@ return [
'addon\futures\event\ShowPromotion',
],
// 用户注册
'MemberRegister' => [
'MemberRegister'=> [
'addon\futures\event\MemberRegister',
],
'OrderPay' => [

View File

@ -37,6 +37,7 @@ class Forder extends BaseModel
if(empty($member_info)){
return $this->success();
}
if ($member_info[ 'fenxiao_id' ] == 0) {
return $this->success();
}
@ -55,7 +56,7 @@ class Forder extends BaseModel
if($is_range && $parent_fenxiao_info){ //减去极差奖励
$direct_push -=$indirect_push;
}else{
$direct_push +5; //管理直推
// $direct_push +5; //管理直推
}
$unit_price=Db::name('futures')->alias('a')
->where([

View File

@ -105,56 +105,44 @@ class Futures extends BaseModel
* @return array
* @throws InvalidArgumentException
*/
public function release($id, $price, $agree_split_order = 0)
public function release($id, $price)
{
$date = model('futures')->getInfo([['id', '=', $id]]);
if (empty($date) || $date['status'] !== 1) {
return $this->error('', '发布失败-db');
}
$basics = $this->getBasicsConfig($date['site_id'])['data']['value'];
model('futures')->startTrans();
try {
//拆单
$futuresInfo = $this->detail($id, $date['site_id'])['data'];
$futuresInfo['status'] = 2;
if ($price >= $futuresInfo['market_price'] * $futuresInfo['total']) {
$futuresInfo['total'] *= 2;
if ($futuresInfo['total'] > pow(2, $basics['order_total_double_times'])) {// 配置单订单商品最大裂变次数
// if($agree_split_order == 0){
// model('futures')->rollback();
// Cache::store('redis_concurrent')->set('addon_futures_stock_'.$id,'1');
// return error(-800, '订单价格达到订单拆分限制,是否同意订单拆分?');
// }
//拆单
$futuresInfo['status'] = 8;
$splitOrderNum = $basics['split_order_num'];
for ($i = 0; $i < $splitOrderNum; $i++) {
$newSmallFuturesId = $this->add([
'site_id' => $futuresInfo['site_id'],
'seller_uid' => $futuresInfo['seller_uid'],
'old_futures_id' => $id,
'goods_id' => $futuresInfo['goods_id'],
'total' => $futuresInfo['total'] / $splitOrderNum,
'unit_price' => $futuresInfo['unit_price'] / $splitOrderNum,
'status' => 1,
'order_id' => $futuresInfo['order_id'],
'created_time' => time()
])['data'];
$this->release($newSmallFuturesId, $price / $splitOrderNum);
}
model('futures')->commit();
return $this->success();
}
}
$basics = $this->getBasicsConfig($date['site_id'])['data']['value'];
$service_price = $date['unit_price'] * $basics['service_price'] / 100; //更改为买入价格
$technical_range = $service_price * $basics['technical_range'] / 100;
if (model('member')->getValue(['member_id' => $date['seller_uid']], 'balance_money') < $service_price) {
return error(-800, '您余额不足!');
}
//拆单
$futuresInfo = $this->detail($id, $date['site_id'])['data'];
$futuresInfo['status'] = 2;
$futuresInfo['start_price'] = $date['start_price'];
$release_time= time() + $basics['release_wait'] * 24 * 60 * 60;// 配置上线延迟时间
if(Db::name('futures_user')->where('member_id', '=',$futuresInfo['seller_uid'])->cache($futuresInfo['seller_uid'].'is_special')->value('is_special')==1){
$release_time=time();
} //排除特殊用户时间限制
if ($price >= $date['start_price'] * $futuresInfo['total']) {
$futuresInfo['total'] *= 2;
if ($futuresInfo['total'] > pow(2, $basics['order_total_double_times'])) {// 配置单订单商品最大裂变次数
//拆单
$res=$this->SplitOrder($id, $price, $futuresInfo, $basics);
if($res['code']>=0){
$futuresInfo['status'] = 8;
model('futures')->update([
'status' => $futuresInfo['status'],
'release_time' => $release_time, // 配置上线延迟时间
], [['id', '=', $id]]);
model('futures')->commit();
}
return $res;
}
}
model('futures')->update([
'status' => $futuresInfo['status'],
'release_time' => $release_time,// 配置上线延迟时间
@ -175,6 +163,46 @@ class Futures extends BaseModel
}
}
/***
* 拆分订单
* @param $id
* @param $price
* @param $futuresInfo
* @param $basics
* @return array
* @throws InvalidArgumentException
*/
private function SplitOrder($id, $price, $futuresInfo, $basics)
{
model('futures')->startTrans();
try {
$splitOrderNum = $basics['split_order_num'];
$futuresInfo['total']/=2;
for ($i = 0; $i < $splitOrderNum; $i++) {
$tempArr=[
'site_id' => $futuresInfo['site_id'],
'seller_uid' => $futuresInfo['seller_uid'],
'member_id' => $futuresInfo['seller_uid'],
'old_futures_id' => $id,
'goods_id' => $futuresInfo['goods_id'],
'start_price' => $futuresInfo['start_price'],
'is_grow' => 1,
'total' => intval($futuresInfo['total']) / $splitOrderNum,
'unit_price' =>floatval($futuresInfo['unit_price']) / $splitOrderNum,
'status' => 1,
'order_id' => $futuresInfo['order_id'],
'created_time' => time()
];
$newSmallFuturesId = $this->add($tempArr)['data'];
$this->release($newSmallFuturesId, $price/$splitOrderNum);
}
model('futures')->commit();
return $this->success();
} catch (\Exception $e) {
model('futures')->rollback();
return $this->error('', $e->getMessage() . $e->getFile() . $e->getLine());
}
}
/**
* 下架到库存
@ -301,6 +329,7 @@ class Futures extends BaseModel
'goods_id' => (int)$date['goods_id'],
'total' => (int)$date['total'],
'unit_price' => $date['price'],
'start_price' => $date['start_price'],
'status' => 1,
'created_time' => time()
]

View File

@ -122,6 +122,7 @@ class User extends BaseModel{
'total' => (int)$info['goods_num'],
'price' => sprintf("%.2f",$info['unit_price'] * $info['goods_num']),
'unit_price' => sprintf("%.2f",$info['unit_price'] * $info['goods_num']),
'start_price' => $info['start_price'],
'status' => 1,
'created_time' => $time,
]);

View File

@ -55,164 +55,164 @@ class FuturesOrderCreate extends OrderCreate
* 订单创建
* @param array $data
*/
public function create($data,$is_special=false)
public function create($data, $is_special = false)
{
//查询出会员相关信息
$calculate_data = $this->calculate($data);
if ($calculate_data[ 'code' ] < 0) return $calculate_data;
if ($calculate_data['code'] < 0) return $calculate_data;
$calculate_data = $calculate_data['data'];
if ($this->error > 0) {
return $this->error([ 'error_code' => $this->error ], $this->error_msg);
return $this->error(['error_code' => $this->error], $this->error_msg);
}
if (!empty($calculate_data[ 'invoice_type' ])) {
if ($calculate_data[ 'invoice_type' ] == 1 && $calculate_data[ 'invoice_full_address' ] == '') {
if (!empty($calculate_data['invoice_type'])) {
if ($calculate_data['invoice_type'] == 1 && $calculate_data['invoice_full_address'] == '') {
//物流,同城
if ($calculate_data[ 'shop_goods_list' ][ 'delivery' ][ 'delivery_type' ] == 'express' || $calculate_data[ 'shop_goods_list' ][ 'delivery' ][ 'delivery_type' ] == 'local') {
$calculate_data[ 'invoice_full_address' ] = $calculate_data[ 'member_address' ][ 'full_address' ] . $calculate_data[ 'member_address' ][ 'address' ];
$calculate_data[ 'shop_goods_list' ][ 'invoice_full_address' ] = $calculate_data[ 'member_address' ][ 'full_address' ] . $calculate_data[ 'member_address' ][ 'address' ];
if ($calculate_data['shop_goods_list']['delivery']['delivery_type'] == 'express' || $calculate_data['shop_goods_list']['delivery']['delivery_type'] == 'local') {
$calculate_data['invoice_full_address'] = $calculate_data['member_address']['full_address'] . $calculate_data['member_address']['address'];
$calculate_data['shop_goods_list']['invoice_full_address'] = $calculate_data['member_address']['full_address'] . $calculate_data['member_address']['address'];
}
//门店
if ($calculate_data[ 'shop_goods_list' ][ 'delivery' ][ 'delivery_type' ] == 'store') {
$delivery_store_info = json_decode($calculate_data[ 'shop_goods_list' ][ 'delivery_store_info' ], true);
$calculate_data[ 'invoice_full_address' ] = $delivery_store_info[ 'full_address' ];
$calculate_data[ 'shop_goods_list' ][ 'invoice_full_address' ] = $delivery_store_info[ 'full_address' ];
if ($calculate_data['shop_goods_list']['delivery']['delivery_type'] == 'store') {
$delivery_store_info = json_decode($calculate_data['shop_goods_list']['delivery_store_info'], true);
$calculate_data['invoice_full_address'] = $delivery_store_info['full_address'];
$calculate_data['shop_goods_list']['invoice_full_address'] = $delivery_store_info['full_address'];
}
}
}
$pay = new Pay();
$out_trade_no = $pay->createOutTradeNo($data[ 'member_id' ]);
$out_trade_no = $pay->createOutTradeNo($data['member_id']);
model('order')->startTrans();
//循环生成多个订单
try {
$pay_money = 0;
$goods_stock_model = new GoodsStock();
$shop_goods_list = $calculate_data[ 'shop_goods_list' ];
$item_delivery = $shop_goods_list[ 'delivery' ] ?? [];
$delivery_type = $item_delivery[ 'delivery_type' ] ?? '';
$shop_goods_list = $calculate_data['shop_goods_list'];
$item_delivery = $shop_goods_list['delivery'] ?? [];
$delivery_type = $item_delivery['delivery_type'] ?? '';
$site_id = $data['site_id'];
$member_id = $data['member_id'];
$express_type_list = (new \app\model\express\Config())->getExpressTypeList($site_id);
$delivery_type_name = $express_type_list[$delivery_type] ?? '';
//订单主表
$order_type = $this->orderType($shop_goods_list, $calculate_data);
$order_no = $this->createOrderNo($shop_goods_list[ 'site_id' ], $data[ 'member_id' ]);
$member_address = $calculate_data[ 'member_address' ];
$member_info= $calculate_data[ 'member_account' ];
$times= $calculate_data[ 'times' ]['original'];
$order_no = $this->createOrderNo($shop_goods_list['site_id'], $data['member_id']);
$member_address = $calculate_data['member_address'];
$member_info = $calculate_data['member_account'];
$times = $calculate_data['times']['original'];
$data_order = [
'order_no' => $order_no,
'site_id' => $site_id,
'site_name' => $shop_goods_list[ 'site_name' ],
'order_from' => $data[ 'order_from' ],
'order_from_name' => $data[ 'order_from_name' ],
'order_type' => $order_type[ 'order_type_id' ],
'order_type_name' => $order_type[ 'order_type_name' ],
'order_status_name' => $order_type[ 'order_status' ][ 'name' ],
'order_status_action' => json_encode($order_type[ 'order_status' ], JSON_UNESCAPED_UNICODE),
'site_name' => $shop_goods_list['site_name'],
'order_from' => $data['order_from'],
'order_from_name' => $data['order_from_name'],
'order_type' => $order_type['order_type_id'],
'order_type_name' => $order_type['order_type_name'],
'order_status_name' => $order_type['order_status']['name'],
'order_status_action' => json_encode($order_type['order_status'], JSON_UNESCAPED_UNICODE),
'out_trade_no' => $out_trade_no,
'member_id' => $member_id,
'name' => $member_address[ 'name' ] ?? '',
'mobile' => $member_address[ 'mobile' ] ?? '',
'telephone' => $member_address[ 'telephone' ] ?? '',
'province_id' => $member_address[ 'province_id' ] ?? '',
'city_id' => $member_address[ 'city_id' ] ?? '',
'district_id' => $member_address[ 'district_id' ] ?? '',
'community_id' => $member_address[ 'community_id' ] ?? '',
'address' => $member_address[ 'address' ] ?? '',
'full_address' => $member_address[ 'full_address' ] ?? '',
'longitude' => $member_address[ 'longitude' ] ?? '',
'latitude' => $member_address[ 'latitude' ] ?? '',
'name' => $member_address['name'] ?? '',
'mobile' => $member_address['mobile'] ?? '',
'telephone' => $member_address['telephone'] ?? '',
'province_id' => $member_address['province_id'] ?? '',
'city_id' => $member_address['city_id'] ?? '',
'district_id' => $member_address['district_id'] ?? '',
'community_id' => $member_address['community_id'] ?? '',
'address' => $member_address['address'] ?? '',
'full_address' => $member_address['full_address'] ?? '',
'longitude' => $member_address['longitude'] ?? '',
'latitude' => $member_address['latitude'] ?? '',
'buyer_ip' => request()->ip(),
'buyer_nickname' => $member_info['nickname'],
'goods_money' => $shop_goods_list[ 'goods_money' ],
'delivery_money' => $shop_goods_list[ 'delivery_money' ],
'coupon_id' => $shop_goods_list[ 'coupon_id' ] ?? 0,
'coupon_money' => $shop_goods_list[ 'coupon_money' ] ?? 0,
'adjust_money' => $shop_goods_list[ 'adjust_money' ],
'invoice_money' => $shop_goods_list[ 'invoice_money' ],
'promotion_money' => $shop_goods_list[ 'promotion_money' ],
'order_money' => $shop_goods_list[ 'order_money' ],
'balance_money' => $shop_goods_list[ 'balance_money' ],
'pay_money' => $shop_goods_list[ 'pay_money' ],
'goods_money' => $shop_goods_list['goods_money'],
'delivery_money' => $shop_goods_list['delivery_money'],
'coupon_id' => $shop_goods_list['coupon_id'] ?? 0,
'coupon_money' => $shop_goods_list['coupon_money'] ?? 0,
'adjust_money' => $shop_goods_list['adjust_money'],
'invoice_money' => $shop_goods_list['invoice_money'],
'promotion_money' => $shop_goods_list['promotion_money'],
'order_money' => $shop_goods_list['order_money'],
'balance_money' => $shop_goods_list['balance_money'],
'pay_money' => $shop_goods_list['pay_money'],
'create_time' => time(),
'is_enable_refund' => 0,
'order_name' => $shop_goods_list[ 'order_name' ],
'goods_num' => $shop_goods_list[ 'goods_num' ],
'order_name' => $shop_goods_list['order_name'],
'goods_num' => $shop_goods_list['goods_num'],
'delivery_type' => $delivery_type,
'delivery_type_name' => $delivery_type_name,
'delivery_store_id' => $shop_goods_list[ 'delivery_store_id' ] ?? 0,
'delivery_store_name' => $shop_goods_list[ 'delivery_store_name' ] ?? '',
'delivery_store_info' => $shop_goods_list[ 'delivery_store_info' ] ?? '',
'buyer_message' => $data[ 'buyer_message' ],
'delivery_store_id' => $shop_goods_list['delivery_store_id'] ?? 0,
'delivery_store_name' => $shop_goods_list['delivery_store_name'] ?? '',
'delivery_store_info' => $shop_goods_list['delivery_store_info'] ?? '',
'buyer_message' => $data['buyer_message'],
'promotion_type' => 'futures',
'promotion_type_name' => '秒杀订单',
'promotion_status_name' => '',
'invoice_delivery_money' => $shop_goods_list[ 'invoice_delivery_money' ] ?? 0,
'taxpayer_number' => $shop_goods_list[ 'taxpayer_number' ] ?? '',
'invoice_rate' => $shop_goods_list[ 'invoice_rate' ] ?? 0,
'invoice_content' => $shop_goods_list[ 'invoice_content' ] ?? '',
'invoice_full_address' => $shop_goods_list[ 'invoice_full_address' ] ?? '',
'is_invoice' => $shop_goods_list[ 'is_invoice' ] ?? 0,
'invoice_type' => $shop_goods_list[ 'invoice_type' ] ?? 0,
'invoice_title' => $shop_goods_list[ 'invoice_title' ] ?? '',
'is_tax_invoice' => $shop_goods_list[ 'is_tax_invoice' ] ?? '',
'invoice_email' => $shop_goods_list[ 'invoice_email' ] ?? '',
'invoice_title_type' => $shop_goods_list[ 'invoice_title_type' ] ?? 0,
'buyer_ask_delivery_time' => $shop_goods_list[ 'buyer_ask_delivery_time' ] ?? '',
'invoice_delivery_money' => $shop_goods_list['invoice_delivery_money'] ?? 0,
'taxpayer_number' => $shop_goods_list['taxpayer_number'] ?? '',
'invoice_rate' => $shop_goods_list['invoice_rate'] ?? 0,
'invoice_content' => $shop_goods_list['invoice_content'] ?? '',
'invoice_full_address' => $shop_goods_list['invoice_full_address'] ?? '',
'is_invoice' => $shop_goods_list['is_invoice'] ?? 0,
'invoice_type' => $shop_goods_list['invoice_type'] ?? 0,
'invoice_title' => $shop_goods_list['invoice_title'] ?? '',
'is_tax_invoice' => $shop_goods_list['is_tax_invoice'] ?? '',
'invoice_email' => $shop_goods_list['invoice_email'] ?? '',
'invoice_title_type' => $shop_goods_list['invoice_title_type'] ?? 0,
'buyer_ask_delivery_time' => $shop_goods_list['buyer_ask_delivery_time'] ?? '',
'store_id' => $shop_goods_list['store_id'],
'promotion_id' => $data[ 'futures_id' ]
'promotion_id' => $data['futures_id']
];
$order_id = model('order')->add($data_order);
$pay_money += $shop_goods_list[ 'pay_money' ];
$pay_money += $shop_goods_list['pay_money'];
//订单项目表
foreach ($shop_goods_list[ 'goods_list' ] as $k_order_goods => $order_goods) {
$data_order_goods = array (
foreach ($shop_goods_list['goods_list'] as $k_order_goods => $order_goods) {
$data_order_goods = array(
'order_id' => $order_id,
'site_id' => $site_id,
'order_no' => $order_no,
'member_id' => $member_id,
'sku_id' => $order_goods[ 'sku_id' ],
'sku_name' => $order_goods[ 'sku_name' ],
'sku_image' => $order_goods[ 'sku_image' ],
'sku_no' => $order_goods[ 'sku_no' ],
'is_virtual' => $order_goods[ 'is_virtual' ],
'goods_class' => $order_goods[ 'goods_class' ],
'goods_class_name' => $order_goods[ 'goods_class_name' ],
'price' => $order_goods[ 'price' ],
'cost_price' => $order_goods[ 'cost_price' ],
'num' => $order_goods[ 'num' ],
'goods_money' => $order_goods[ 'goods_money' ],
'cost_money' => $order_goods[ 'cost_price' ] * $order_goods[ 'num' ],
'goods_id' => $order_goods[ 'goods_id' ],
'sku_id' => $order_goods['sku_id'],
'sku_name' => $order_goods['sku_name'],
'sku_image' => $order_goods['sku_image'],
'sku_no' => $order_goods['sku_no'],
'is_virtual' => $order_goods['is_virtual'],
'goods_class' => $order_goods['goods_class'],
'goods_class_name' => $order_goods['goods_class_name'],
'price' => $order_goods['price'],
'cost_price' => $order_goods['cost_price'],
'num' => $order_goods['num'],
'goods_money' => $order_goods['goods_money'],
'cost_money' => $order_goods['cost_price'] * $order_goods['num'],
'goods_id' => $order_goods['goods_id'],
'delivery_status' => 0,
'delivery_status_name' => '未发货',
'real_goods_money' => $order_goods[ 'real_goods_money' ],
'coupon_money' => $order_goods[ 'coupon_money' ] ?? 0,
'promotion_money' => $order_goods[ 'promotion_money' ],
'goods_name' => $order_goods[ 'goods_name' ],
'sku_spec_format' => $order_goods[ 'sku_spec_format' ],
'real_goods_money' => $order_goods['real_goods_money'],
'coupon_money' => $order_goods['coupon_money'] ?? 0,
'promotion_money' => $order_goods['promotion_money'],
'goods_name' => $order_goods['goods_name'],
'sku_spec_format' => $order_goods['sku_spec_format'],
'store_id' => $shop_goods_list['store_id']
);
$order_goods_id = model('order_goods')->add($data_order_goods);
$calculate_data[ 'shop_goods_list' ][ 'goods_list' ][ $k_order_goods ][ 'order_goods_id' ] = $order_goods_id;
$calculate_data['shop_goods_list']['goods_list'][$k_order_goods]['order_goods_id'] = $order_goods_id;
}
$futures_model = new Futures;
$futures_info = $futures_model->orderCreate($data['futures_id'],$order_id,$member_id);
if ($futures_info[ 'code' ] != 0) {
$futures_info = $futures_model->orderCreate($data['futures_id'], $order_id, $member_id);
if ($futures_info['code'] != 0) {
model('order')->rollback();
return $futures_info;
}
// 提前秒杀扣除钻石
if($calculate_data['times']['is_early']){
if ($calculate_data['times']['is_early']) {
$member_account = new MemberAccount();
$member_account->addMemberAccount($site_id, $data['member_id'], 'diamond', -1, 'intdiamond', '秒杀抵扣猕猴桃', '会员抢购抵猕猴桃',$order_id);
$member_account->addMemberAccount($site_id, $data['member_id'], 'diamond', -1, 'intdiamond', '秒杀抵扣猕猴桃', '会员抢购抵猕猴桃', $order_id);
}
$result_list = event('OrderCreate', [ 'order_id' => $order_id, 'site_id' => $shop_goods_list[ 'site_id' ],'create_data' => $calculate_data ]);
$result_list = event('OrderCreate', ['order_id' => $order_id, 'site_id' => $shop_goods_list['site_id'], 'create_data' => $calculate_data]);
if (!empty($result_list)) {
foreach ($result_list as $k => $v) {
if (!empty($v) && $v[ 'code' ] < 0) {
if (!empty($v) && $v['code'] < 0) {
model('order')->rollback();
return $v;
}
@ -225,7 +225,7 @@ class FuturesOrderCreate extends OrderCreate
$execute_time = $times['miaosha_end_time'] ?? '';
if ($execute_time) {
$cron_model = new Cron();
$execute_time +=strtotime(date('Ymd'));
$execute_time += strtotime(date('Ymd'));
$cron_model->addCron(1, 0, "订单自动关闭", "CronOrderClose", $execute_time, $order_id);
} else {
$this->addOrderCronClose($order_id, $shop_goods_list['site_id']);//增加关闭订单自动事件
@ -247,13 +247,13 @@ class FuturesOrderCreate extends OrderCreate
$data = $this->initMemberAddress($data);
$data = $this->initMemberAccount($data);//初始化会员账户
//余额付款
if ($data[ 'is_balance' ] > 0) {
$this->member_balance_money = $data[ 'member_account' ][ 'balance_total' ] ?? 0;
if ($data['is_balance'] > 0) {
$this->member_balance_money = $data['member_account']['balance_total'] ?? 0;
}
$member_model = new Member();
$result = $member_model->checkPayPassword($data["member_id"], $data["pay_password"]);
if ($result["code"] < 0) {
return error(-1,'支付密码不正确');
return error(-1, '支付密码不正确');
}
$member_id = $data['member_id'];
$futures_id = $data['futures_id'];
@ -261,95 +261,94 @@ class FuturesOrderCreate extends OrderCreate
$condition = array(
['id', '=', $futures_id],
['site_id', '=', $site_id],
['status', 'in', [2,7]],
['status', 'in', [2, 7]],
['release_time', '<', time()],
);
$futures_info = model('futures')->getInfo($condition) ?? [];
if(empty($futures_info)) return $this->error([], '该秒杀不存在!');
if (empty($futures_info)) return $this->error([], '该秒杀不存在!');
$futuresModel = new FuturesModel;
$data['times'] = $futuresModel->checkTimes($site_id, $member_id, $futures_info['status']);
if($data['times']['code'] != 0){
if ($data['times']['code'] != 0) {
return $data['times'];
}
$data['times'] = $data['times']['data'];
$basics = $futuresModel->getBasicsConfig($site_id)['data']['value'];
$data['futures_user_info'] = model('futures_user')->getInfo([['member_id','=',$data['member_id']]]);
$data['futures_user_info'] = model('futures_user')->getInfo([['member_id', '=', $data['member_id']]]);
//检查钻石数量
if($data['times']['is_early'] && $data['futures_user_info']['is_special'] == 0){
if($data['member_account']['diamond'] <= 0){
return error(-1,'钻石不足,不可提前秒杀');
if ($data['times']['is_early'] && $data['futures_user_info']['is_special'] == 0) {
if ($data['member_account']['diamond'] <= 0) {
return error(-1, '钻石不足,不可提前秒杀');
}
}
if(empty($data['futures_user_info'] )){
return error(-1,'注册错误,请使用小程序注册');
if (empty($data['futures_user_info'])) {
return error(-1, '注册错误,请使用小程序注册');
}
$w=[
['seller_uid','=',$member_id],
['status','in',[1,2]],
['created_time','BETWEEN',[strtotime(date("Y-m-d", time())),time()]]
$w = [
['member_id', '=', $member_id],
['status', 'in', [1, 2, 6]],
['created_time', 'BETWEEN', [strtotime(date("Y-m-d", time())), time()]]
];
$jianlou_start_time=strtotime(date("Y-m-d", time()))+$data['times']['original']['jianlou_start_time'];
if(time()<=$jianlou_start_time&& $basics['buying_order_limit'] && $data['futures_user_info']['is_special'] == 0 && model('futures')->getCount($w,'id')>=$basics['buying_order_limit']){
return error(-1,"每天只允许抢购{$basics['buying_order_limit']}");
$jianlou_start_time = strtotime(date("Y-m-d", time())) + $data['times']['original']['jianlou_start_time'];
if (time() <= $jianlou_start_time && $basics['buying_order_limit'] && model('futures')->getCount($w, 'id') >= $basics['buying_order_limit'] && $data['futures_user_info']['is_special'] == 0) {
return error(-1, "每天只允许抢购{$basics['buying_order_limit']}");
}
// 判断用户是否有足够多的购买机会
if($data['futures_user_info']['business_num'] >= $basics['order_restrictions_num'] && $data['futures_user_info']['is_special'] == 0){
return error(-1,'下单次数达到限制,需提货恢复下单');
if ($data['futures_user_info']['business_num'] >= $basics['order_restrictions_num'] && $data['futures_user_info']['is_special'] == 0) {
return error(-1, '下单次数达到限制,需提货恢复下单');
}
// 判断是否本人购买
if($data['member_id'] == $futures_info['seller_uid'] && $data['futures_user_info']['is_special'] == 0){
return error(-1,'本人订单不可本人购买');
if ($data['member_id'] == $futures_info['seller_uid'] && $data['futures_user_info']['is_special'] == 0) {
return error(-1, '本人订单不可本人购买');
}
// 判断惩罚时间
if($data['futures_user_info']['punish_time'] >= time() && $data['futures_user_info']['is_special'] == 0){
return error(-1,'有违规订单,在惩罚时间内,惩罚时间到 '.date("Y-m-d H:i:s", $data['futures_user_info']['punish_time']));
if ($data['futures_user_info']['punish_time'] >= time() && $data['futures_user_info']['is_special'] == 0) {
return error(-1, '有违规订单,在惩罚时间内,惩罚时间到 ' . date("Y-m-d H:i:s", $data['futures_user_info']['punish_time']));
}
$futures_id = $futures_info['id'];
$data['futures_id'] = $futures_id;
$data['futures_info'] = $futuresModel->detail($futures_id,$site_id)['data'];
$data['futures_info'] = $futuresModel->detail($futures_id, $site_id)['data'];
$data['sku_id'] = $futures_info['goods_id'];
$data['num'] = $futures_info['total'];
//商品列表信息
$shop_goods_list = $this->getOrderGoodsCalculate($data);
$data[ 'shop_goods_list' ] = $this->shopOrderCalculate($shop_goods_list, $data);
if (empty($data[ 'shop_goods_list' ]['goods_list'])) return $this->error([], '卡项中没有可以提货的商品!');
$data['shop_goods_list'] = $this->shopOrderCalculate($shop_goods_list, $data);
if (empty($data['shop_goods_list']['goods_list'])) return $this->error([], '卡项中没有可以提货的商品!');
$data[ 'shop_goods_list' ]['goods_list'][0]['price'] = number_format($futures_info['price']/$futures_info['total'], 2);
$data['shop_goods_list']['goods_list'][0]['price'] = number_format($futures_info['price'] / $futures_info['total'], 2);
//总结计算
$data[ 'delivery_money' ] = $this->delivery_money;
$data[ 'coupon_money' ] = $this->coupon_money;
$data[ 'adjust_money' ] = $this->adjust_money;
$data[ 'invoice_money' ] = $this->invoice_money;
$data[ 'invoice_delivery_money' ] = $this->invoice_delivery_money;
$data[ 'promotion_money' ] = 0;
$data['delivery_money'] = $this->delivery_money;
$data['coupon_money'] = $this->coupon_money;
$data['adjust_money'] = $this->adjust_money;
$data['invoice_money'] = $this->invoice_money;
$data['invoice_delivery_money'] = $this->invoice_delivery_money;
$data['promotion_money'] = 0;
// $data[ 'promotion_money' ] = $this->promotion_money;
$data[ 'order_money' ] = $this->order_money;
$data[ 'balance_money' ] = $this->balance_money;
$data[ 'pay_money' ] = $this->pay_money;
$data[ 'goods_money' ] = $this->goods_money;
$data[ 'goods_num' ] = $this->goods_num;
$data[ 'is_virtual' ] = $this->is_virtual;
$data['order_money'] = $this->order_money;
$data['balance_money'] = $this->balance_money;
$data['pay_money'] = $this->pay_money;
$data['goods_money'] = $this->goods_money;
$data['goods_num'] = $this->goods_num;
$data['is_virtual'] = $this->is_virtual;
$this->goods_money = $futures_info['price'];
$this->order_money = $futures_info['price'];
$this->pay_money = $futures_info['price'];
$this->promotion_money = 0;
$data[ 'shop_goods_list' ]['goods_money'] = $futures_info['price'];
$data[ 'shop_goods_list' ]['order_money'] = $futures_info['price'];
$data[ 'shop_goods_list' ]['pay_money'] = $futures_info['price'];
$data[ 'shop_goods_list' ]['promotion_money'] = $futures_info['price'];
$data[ 'goods_money' ] = $futures_info['price'];
$data[ 'order_money' ] = $futures_info['price'];
$data[ 'pay_money' ] = $futures_info['price'];
$data['shop_goods_list']['goods_money'] = $futures_info['price'];
$data['shop_goods_list']['order_money'] = $futures_info['price'];
$data['shop_goods_list']['pay_money'] = $futures_info['price'];
$data['shop_goods_list']['promotion_money'] = $futures_info['price'];
$data['goods_money'] = $futures_info['price'];
$data['order_money'] = $futures_info['price'];
$data['pay_money'] = $futures_info['price'];
return $this->success($data);
}
@ -360,77 +359,77 @@ class FuturesOrderCreate extends OrderCreate
public function orderPayment($data)
{
$calculate_data = $this->calculate($data);
if ($calculate_data[ 'code' ] < 0)
if ($calculate_data['code'] < 0)
return $calculate_data;
$calculate_data = $calculate_data['data'];
//1、查询会员优惠券
$calculate_data[ 'shop_goods_list' ][ 'coupon_list' ] = [];
$calculate_data['shop_goods_list']['coupon_list'] = [];
$express_type = [];
if ($this->is_virtual == 0) {
foreach ($calculate_data[ 'shop_goods_list' ][ 'deliver_sort' ] as $type) {
foreach ($calculate_data['shop_goods_list']['deliver_sort'] as $type) {
// 物流
if ($type == 'express' && $calculate_data[ 'shop_goods_list' ][ 'express_config' ][ 'is_use' ] == 1) {
$title = $calculate_data[ 'shop_goods_list' ][ 'express_config' ][ 'value' ][ 'express_name' ];
if ($type == 'express' && $calculate_data['shop_goods_list']['express_config']['is_use'] == 1) {
$title = $calculate_data['shop_goods_list']['express_config']['value']['express_name'];
if ($title == '') {
$title = Express::express_type[ 'express' ][ 'title' ];
$title = Express::express_type['express']['title'];
}
$express_type[] = [ 'title' => $title, 'name' => 'express' ];
$express_type[] = ['title' => $title, 'name' => 'express'];
}
// 自提
if ($type == 'store' && $calculate_data[ 'shop_goods_list' ][ 'store_config' ][ 'is_use' ] == 1) {
if ($type == 'store' && $calculate_data['shop_goods_list']['store_config']['is_use'] == 1) {
//根据坐标查询门店
$store_model = new Store();
$store_condition = array (
[ 'site_id', '=', $data[ 'site_id' ] ],
[ 'is_pickup', '=', 1 ],
[ 'status', '=', 1 ],
[ 'is_frozen', '=', 0 ],
$store_condition = array(
['site_id', '=', $data['site_id']],
['is_pickup', '=', 1],
['status', '=', 1],
['is_frozen', '=', 0],
);
$latlng = array (
'lat' => $data[ 'latitude' ],
'lng' => $data[ 'longitude' ],
$latlng = array(
'lat' => $data['latitude'],
'lng' => $data['longitude'],
);
$store_list_result = $store_model->getLocationStoreList($store_condition, '*', $latlng);
$store_list = $store_list_result[ 'data' ];
$title = $calculate_data[ 'shop_goods_list' ][ 'store_config' ][ 'value' ][ 'store_name' ];
$store_list = $store_list_result['data'];
$title = $calculate_data['shop_goods_list']['store_config']['value']['store_name'];
if ($title == '') {
$title = Express::express_type[ 'store' ][ 'title' ];
$title = Express::express_type['store']['title'];
}
$express_type[] = [ 'title' => $title, 'name' => 'store', 'store_list' => $store_list ];
$express_type[] = ['title' => $title, 'name' => 'store', 'store_list' => $store_list];
}
// 外卖
if ($type == 'local' && $calculate_data[ 'shop_goods_list' ][ 'local_config' ][ 'is_use' ] == 1) {
if ($type == 'local' && $calculate_data['shop_goods_list']['local_config']['is_use'] == 1) {
//查询本店的通讯地址
$title = $calculate_data[ 'shop_goods_list' ][ 'local_config' ][ 'value' ][ 'local_name' ];
$title = $calculate_data['shop_goods_list']['local_config']['value']['local_name'];
if ($title == '') {
$title = '外卖配送';
}
$store_model = new Store();
$store_condition = array (
[ 'site_id', '=', $data[ 'site_id' ] ]
$store_condition = array(
['site_id', '=', $data['site_id']]
);
if (addon_is_exit('store', $data[ 'site_id' ])) {
$store_condition[] = [ 'is_o2o', '=', 1 ];
$store_condition[] = [ 'status', '=', 1 ];
$store_condition[] = [ 'is_frozen', '=', 0 ];
if (addon_is_exit('store', $data['site_id'])) {
$store_condition[] = ['is_o2o', '=', 1];
$store_condition[] = ['status', '=', 1];
$store_condition[] = ['is_frozen', '=', 0];
} else {
$store_condition[] = ['is_default', '=', 1];
}
$latlng = array (
'lat' => $data[ 'latitude' ],
'lng' => $data[ 'longitude' ],
$latlng = array(
'lat' => $data['latitude'],
'lng' => $data['longitude'],
);
$store_list_result = $store_model->getLocationStoreList($store_condition, '*', $latlng);
$store_list = $store_list_result[ 'data' ];
$store_list = $store_list_result['data'];
$express_type[] = [ 'title' => $title, 'name' => 'local', 'store_list' => $store_list ];
$express_type[] = ['title' => $title, 'name' => 'local', 'store_list' => $store_list];
}
}
}
$calculate_data[ 'shop_goods_list' ][ 'express_type' ] = $express_type;
$calculate_data['shop_goods_list']['express_type'] = $express_type;
$payment_event_data = event('OrderPayment', $calculate_data);
if (!empty($payment_event_data)) {
@ -451,7 +450,7 @@ class FuturesOrderCreate extends OrderCreate
$goods_list = $this->getShopGoodsList($data);
$this->promotion_money = 0;
$goods_list[ 'promotion_money' ] = 0;
$goods_list['promotion_money'] = 0;
$shop_goods_list = $goods_list;
return $shop_goods_list;
}
@ -466,32 +465,32 @@ class FuturesOrderCreate extends OrderCreate
*/
public function shopOrderCalculate($shop_goods, $data)
{
$site_id = $shop_goods[ 'site_id' ];
$site_id = $shop_goods['site_id'];
//交易配置
$config_model = new Config();
$order_config_result = $config_model->getOrderEventTimeConfig($site_id);
$order_config = $order_config_result[ 'data' ];
$order_config = $order_config_result['data'];
$shop_goods[ 'order_config' ] = $order_config[ 'value' ] ?? [];
$shop_goods['order_config'] = $order_config['value'] ?? [];
$promotion_money = 0;
foreach ($shop_goods[ 'goods_list' ] as $k => $v) {
foreach ($shop_goods['goods_list'] as $k => $v) {
$item_goods_money = $v['goods_money'];
$item_promotion_money = $item_goods_money;
$real_goods_money = $item_goods_money - $item_promotion_money;
$shop_goods[ 'goods_list' ][ $k ][ 'real_goods_money' ] = $real_goods_money;
$shop_goods[ 'goods_list' ][ $k ][ 'promotion_money' ] = $item_promotion_money;
$shop_goods['goods_list'][$k]['real_goods_money'] = $real_goods_money;
$shop_goods['goods_list'][$k]['promotion_money'] = $item_promotion_money;
$promotion_money += $item_promotion_money;
}
$goods_money = $shop_goods['goods_money'];
$shop_goods['promotion_money'] = $promotion_money;
$shop_goods[ 'is_free_delivery' ] = true;//
$shop_goods['is_free_delivery'] = true;//
//定义计算金额
$delivery_money = 0; //配送费用
$promotion_money = $shop_goods[ 'promotion_money' ]; //优惠费用(满减)
$promotion_money = $shop_goods['promotion_money']; //优惠费用(满减)
$coupon_money = 0; //优惠券费用
$adjust_money = 0; //调整金额
$invoice_money = 0; //发票金额
@ -503,116 +502,116 @@ class FuturesOrderCreate extends OrderCreate
//计算邮费
if ($this->is_virtual == 1) {
//虚拟订单 运费为0
$shop_goods[ 'delivery' ][ 'delivery_type' ] = '';
$shop_goods['delivery']['delivery_type'] = '';
} else {
$express_config_model = new ExpressConfig();
$deliver_type = $express_config_model->getDeliverTypeSort($site_id);
$deliver_type = $deliver_type[ 'data' ];
$shop_goods[ 'deliver_sort' ] = explode(',', $deliver_type[ 'value' ][ 'deliver_type' ]);
$deliver_type = $deliver_type['data'];
$shop_goods['deliver_sort'] = explode(',', $deliver_type['value']['deliver_type']);
//查询店铺是否开启快递配送
$express_config_result = $express_config_model->getExpressConfig($site_id);
$express_config = $express_config_result[ 'data' ];
$shop_goods[ 'express_config' ] = $express_config;
$express_config = $express_config_result['data'];
$shop_goods['express_config'] = $express_config;
//查询店铺是否开启门店自提
$store_config_result = $express_config_model->getStoreConfig($site_id);
$store_config = $store_config_result[ 'data' ];
$shop_goods[ 'store_config' ] = $store_config;
$store_config = $store_config_result['data'];
$shop_goods['store_config'] = $store_config;
//查询店铺是否开启外卖配送
$local_config_result = $express_config_model->getLocalDeliveryConfig($site_id);
$local_config = $local_config_result[ 'data' ];
$shop_goods[ 'local_config' ] = $local_config;
$local_config = $local_config_result['data'];
$shop_goods['local_config'] = $local_config;
//如果本地配送开启, 则查询出本地配送的配置
if ($shop_goods[ 'local_config' ][ 'is_use' ] == 1 && isset($data[ 'delivery' ][ 'store_id' ])) {
if ($shop_goods['local_config']['is_use'] == 1 && isset($data['delivery']['store_id'])) {
$local_model = new Local();
$local_info_result = $local_model->getLocalInfo([ [ 'site_id', '=', $site_id ], ['store_id', '=', $data[ 'delivery' ][ 'store_id' ] ] ]);
$local_info = $local_info_result[ 'data' ];
$shop_goods[ 'local_config' ][ 'info' ] = $local_info;
} else{
$shop_goods[ 'local_config' ][ 'info' ] = [];
$local_info_result = $local_model->getLocalInfo([['site_id', '=', $site_id], ['store_id', '=', $data['delivery']['store_id']]]);
$local_info = $local_info_result['data'];
$shop_goods['local_config']['info'] = $local_info;
} else {
$shop_goods['local_config']['info'] = [];
}
$delivery_array = $data[ 'delivery' ] ?? [];
$delivery_type = $delivery_array[ 'delivery_type' ] ?? 'express';
$delivery_array = $data['delivery'] ?? [];
$delivery_type = $delivery_array['delivery_type'] ?? 'express';
if ($delivery_type == 'store') {
if (isset($data[ 'delivery' ][ 'delivery_type' ]) && $data[ 'delivery' ][ 'delivery_type' ] == 'store') {
if (isset($data['delivery']['delivery_type']) && $data['delivery']['delivery_type'] == 'store') {
//门店自提
$shop_goods[ 'delivery' ][ 'delivery_type' ] = 'store';
if ($shop_goods[ 'store_config' ][ 'is_use' ] == 0) {
$shop_goods['delivery']['delivery_type'] = 'store';
if ($shop_goods['store_config']['is_use'] == 0) {
$this->error = 1;
$this->error_msg = '门店自提方式未开启!';
}
if (empty($data[ 'delivery' ][ 'store_id' ])) {
if (empty($data['delivery']['store_id'])) {
$this->error = 1;
$this->error_msg = '门店未选择!';
}
$shop_goods[ 'delivery' ][ 'store_id' ] = $data[ 'delivery' ][ 'store_id' ];
$shop_goods[ 'buyer_ask_delivery_time' ] = $data[ 'buyer_ask_delivery_time' ];
$shop_goods['delivery']['store_id'] = $data['delivery']['store_id'];
$shop_goods['buyer_ask_delivery_time'] = $data['buyer_ask_delivery_time'];
$shop_goods = $this->storeOrderData($shop_goods, $data);
$store_id = $data[ 'delivery' ][ 'store_id' ] ?? 0;
$store_id = $data['delivery']['store_id'] ?? 0;
}
} else {
if (empty($data[ 'member_address' ])) {
$shop_goods[ 'delivery' ][ 'delivery_type' ] = 'express';
if (empty($data['member_address'])) {
$shop_goods['delivery']['delivery_type'] = 'express';
$this->error = 1;
$this->error_msg = '未配置默认收货地址!';
} else {
if (!isset($data[ 'delivery' ][ 'delivery_type' ]) || $data[ 'delivery' ][ 'delivery_type' ] == 'express') {
if ($shop_goods[ 'express_config' ][ 'is_use' ] == 1) {
if (!isset($data['delivery']['delivery_type']) || $data['delivery']['delivery_type'] == 'express') {
if ($shop_goods['express_config']['is_use'] == 1) {
//物流配送
$express = new Express();
$express_fee_result = $express->calculate($shop_goods, $data);
if ($express_fee_result[ 'code' ] < 0) {
if ($express_fee_result['code'] < 0) {
$this->error = 1;
$this->error_msg = $express_fee_result[ 'message' ];
$this->error_msg = $express_fee_result['message'];
$delivery_fee = 0;
} else {
$delivery_fee = $express_fee_result[ 'data' ][ 'delivery_fee' ];
$delivery_fee = $express_fee_result['data']['delivery_fee'];
}
} else {
$this->error = 1;
$this->error_msg = '物流配送方式未开启!';
$delivery_fee = 0;
}
$shop_goods[ 'delivery' ][ 'delivery_type' ] = 'express';
} else if ($data[ 'delivery' ][ 'delivery_type' ] == 'local') {
if (empty($data[ 'delivery' ][ 'store_id' ])) {
$shop_goods['delivery']['delivery_type'] = 'express';
} else if ($data['delivery']['delivery_type'] == 'local') {
if (empty($data['delivery']['store_id'])) {
$this->setError(1, '门店未选择!');
}
//外卖配送
$shop_goods[ 'delivery' ][ 'delivery_type' ] = 'local';
if ($shop_goods[ 'local_config' ][ 'is_use' ] == 0) {
$shop_goods['delivery']['delivery_type'] = 'local';
if ($shop_goods['local_config']['is_use'] == 0) {
$this->error = 1;
$this->error_msg = '外卖配送方式未开启!';
} else {
if (empty($data[ 'delivery' ][ 'store_id' ])) {
if (empty($data['delivery']['store_id'])) {
$this->setError(1, '门店未选择!');
}
$local_delivery_time = 0;
if (!empty($data[ 'buyer_ask_delivery_time' ])) {
$local_delivery_time = $data[ 'buyer_ask_delivery_time' ];
if (!empty($data['buyer_ask_delivery_time'])) {
$local_delivery_time = $data['buyer_ask_delivery_time'];
}
$shop_goods[ 'buyer_ask_delivery_time' ] = $local_delivery_time;
$shop_goods['buyer_ask_delivery_time'] = $local_delivery_time;
$local_model = new Local();
$data['unlimited_start_money'] = 1; // 不限制起送价
$local_result = $local_model->calculate($shop_goods, $data);
$shop_goods[ 'delivery' ][ 'start_money' ] = 0;
if ($local_result[ 'code' ] < 0) {
$this->error = $local_result[ 'data' ][ 'code' ];
$this->error_msg = $local_result[ 'message' ];
$shop_goods[ 'delivery' ][ 'start_money' ] = $local_result[ 'data' ][ 'start_money_array' ][ 0 ] ?? 0;
$shop_goods['delivery']['start_money'] = 0;
if ($local_result['code'] < 0) {
$this->error = $local_result['data']['code'];
$this->error_msg = $local_result['message'];
$shop_goods['delivery']['start_money'] = $local_result['data']['start_money_array'][0] ?? 0;
} else {
if (!empty($local_result[ 'data' ][ 'error_code' ])) {
$this->error = $local_result[ 'data' ][ 'code' ];
$this->error_msg = $local_result[ 'data' ][ 'error' ];
if (!empty($local_result['data']['error_code'])) {
$this->error = $local_result['data']['code'];
$this->error_msg = $local_result['data']['error'];
}
}
$shop_goods[ 'delivery' ][ 'error' ] = $this->error;
$shop_goods[ 'delivery' ][ 'error_msg' ] = $this->error_msg;
$store_id = $data[ 'delivery' ][ 'store_id' ] ?? 0;
$shop_goods['delivery']['error'] = $this->error;
$shop_goods['delivery']['error_msg'] = $this->error_msg;
$store_id = $data['delivery']['store_id'] ?? 0;
}
}
}
@ -620,7 +619,7 @@ class FuturesOrderCreate extends OrderCreate
}
//是否符合免邮
$is_free_delivery = $shop_goods[ 'is_free_delivery' ] ?? false;
$is_free_delivery = $shop_goods['is_free_delivery'] ?? false;
if ($is_free_delivery) {
$delivery_money = 0;
}
@ -628,8 +627,8 @@ class FuturesOrderCreate extends OrderCreate
//发票相关
$shop_goods = $this->invoice($shop_goods, $data);
$order_money = $goods_money + $delivery_money - $promotion_money + $shop_goods[ 'invoice_money' ] + $shop_goods[ 'invoice_delivery_money' ];
$shop_goods[ 'order_money' ] = $order_money;
$order_money = $goods_money + $delivery_money - $promotion_money + $shop_goods['invoice_money'] + $shop_goods['invoice_delivery_money'];
$shop_goods['order_money'] = $order_money;
if ($order_money < 0) {
$order_money = 0;
}
@ -639,28 +638,28 @@ class FuturesOrderCreate extends OrderCreate
$this->balance_money += $balance_money;//累计余额
//总结计算
$shop_goods[ 'store_id' ] = $store_id;
$shop_goods[ 'goods_money' ] = $goods_money;
$shop_goods[ 'delivery_money' ] = $delivery_money;
$shop_goods[ 'coupon_money' ] = $coupon_money;
$shop_goods[ 'adjust_money' ] = $adjust_money;
$shop_goods[ 'promotion_money' ] = $promotion_money;
$shop_goods[ 'order_money' ] = $order_money;
$shop_goods[ 'balance_money' ] = $balance_money;
$shop_goods[ 'pay_money' ] = $pay_money;
$shop_goods['store_id'] = $store_id;
$shop_goods['goods_money'] = $goods_money;
$shop_goods['delivery_money'] = $delivery_money;
$shop_goods['coupon_money'] = $coupon_money;
$shop_goods['adjust_money'] = $adjust_money;
$shop_goods['promotion_money'] = $promotion_money;
$shop_goods['order_money'] = $order_money;
$shop_goods['balance_money'] = $balance_money;
$shop_goods['pay_money'] = $pay_money;
$this->goods_money += $goods_money;
$this->delivery_money += $delivery_money;
$this->coupon_money += $coupon_money;
$this->adjust_money += $adjust_money;
$this->invoice_money += $shop_goods[ 'invoice_money' ];
$this->invoice_delivery_money += $shop_goods[ 'invoice_delivery_money' ];
$this->invoice_money += $shop_goods['invoice_money'];
$this->invoice_delivery_money += $shop_goods['invoice_delivery_money'];
$this->promotion_money += $promotion_money;
$this->order_money += $order_money;
$this->pay_money += $pay_money;
$this->goods_num += $shop_goods[ 'goods_num' ];
$this->order_name = string_split($this->order_name, ',', $shop_goods[ 'order_name' ]);
$this->goods_num += $shop_goods['goods_num'];
$this->order_name = string_split($this->order_name, ',', $shop_goods['order_name']);
return $shop_goods;
}

View File

@ -73,7 +73,7 @@
<label class="layui-form-label img-upload-lable short-label"><span class="required">*</span>订单数量:</label>
<div class="layui-input-inline">
<input type="number" name="info[order_num]" value="1" lay-verify="required|number" min="1" placeholder="请输入订单数量" autocomplete="off" class="layui-input len-long">
<div class="tips">赠送的订单数量</div>
<div class="tips">系统会产生指定的订单数量</div>
</div>
</div>
<div class="layui-form-item">
@ -83,11 +83,19 @@
<div class="tips">每份订单中商品的数量</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label img-upload-lable short-label"><span class="required">*</span>商品价格:</label>
<div class="layui-input-inline">
<input type="number" name="info[unit_price]" value="0" lay-verify="required|number" placeholder="请单件商品的价格!" autocomplete="off" class="layui-input len-long">
<div class="tips">首单单个商品卖出价格</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label img-upload-lable short-label"><span class="required">*</span>初始均价:</label>
<div class="layui-input-inline">
<input type="number" name="info[unit_price]" value="0" lay-verify="required|number" placeholder="请输入初始价格!" autocomplete="off" class="layui-input len-long">
<div class="tips">所有订单的初始均价,订单均价(该价格除以商品数量)不能超过<span id="maxAverage">0</span></div>
<input type="number" name="info[start_price]" value="0" lay-verify="required|number" placeholder="请输入初始价格!" autocomplete="off" class="layui-input len-long">
<div class="tips">用户裂变起始价格<span id="maxAverage">0</span></div>
</div>
</div>
</div>
@ -123,7 +131,7 @@
// layer.msg('商品价格不能低于售卖价格!');
// return false;
// }
// if(parseFloat(field['info[unit_price]']) >= parseFloat(goods_info['market_price'])){
// if(parseFloat(field['info[start_price]']) >= parseFloat(goods_info['market_price'])){
// console.log(field['info[unit_price]'],goods_info['market_price']);
// layer.msg('商品价格必须低于原价(划线价)');
// return false;
@ -177,7 +185,7 @@
// 信息记录
goods_info = info = JSON.parse(info);
$("#maxAverage").html(info.market_price);
$("[name='info[unit_price]']").val(info.price);
$("[name='info[start_price]']").val(info.price);
$(".params-content").removeClass('hide');
rendering(info);
}

View File

@ -165,7 +165,6 @@ class Member extends BaseApi
return $this->response($this->error("", "当前手机号已存在"));
} else {
$code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);// 生成4位随机数左侧补0
$message_model = new Message();
$res = $message_model->sendMessage([
'type' => 'code', "mobile" => $mobile,
@ -298,7 +297,13 @@ class Member extends BaseApi
if ($token[ 'code' ] < 0) return $this->response($token);
$code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);// 生成4位随机数左侧补0
$message_model = new Message();
$res = $message_model->sendMessage([ 'type' => 'code', "member_id" => $this->member_id, "site_id" => $this->site_id, "code" => $code, "support_type" => [ "sms" ], "keywords" => "MEMBER_PAY_PASSWORD" ]);
$res = $message_model->sendMessage(
[ 'type' => 'code',
"member_id" => $this->member_id,
"site_id" => $this->site_id,
"code" => $code,
"support_type" => [ "sms" ],
"keywords" => "MEMBER_PAY_PASSWORD" ]);
// $code=6666;
// $res['code']=0;
if ($res[ "code" ] >= 0) {

View File

@ -5,7 +5,6 @@
* Copy right 2019-2029 成都云之牛科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.cdcloudshop.com
* =========================================================
*/
@ -61,7 +60,8 @@ class Task extends Controller
/**
*检测自动任务是否人在进行
*/
public function checkCron(){
public function checkCron()
{
$cron_model = new \app\model\system\Cron();
$result = $cron_model->checkCron();
return $result;

View File

@ -132,6 +132,7 @@ class MemberAccount extends BaseModel
$from_type[ 'point' ][ 'sell' ] = [ 'type_name' => '秒杀赠送积分', 'type_url' => '' ];
$from_type[ 'balance' ][ 'transfer' ] = [ 'type_name' => '转账', 'type_url' => '' ];
$from_type[ 'balance_money' ][ 'transfer' ] = [ 'type_name' => '转账', 'type_url' => '' ];
$from_type[ 'balance' ]['diamond'] = [ 'type_name' => '赠送猕猴桃', 'type_url' => '' ];
$from_type[ 'balance' ]['intdiamond'] = [ 'type_name' => '提前秒杀猕猴桃', 'type_url' => '' ];
@ -184,7 +185,7 @@ class MemberAccount extends BaseModel
}else if ((float) $account_new_data < 0) {
model('member_account')->rollback();
$msg = '';
if ($account_type == 'balance') {
if ($account_type == 'balance' || $account_type='balance_money') {
$msg = '账户余额不足';
} elseif ($account_type == 'point') {
$msg = '账户积分不足';

View File

@ -68,70 +68,66 @@ class Cron extends BaseModel
public function execute()
{
$system_config_model = new SystemConfig();
$config = $system_config_model->getSystemConfig()[ 'data' ] ?? [];
$is_open_queue = $config[ 'is_open_queue' ] ?? 0;
$config = $system_config_model->getSystemConfig()['data'] ?? [];
$is_open_queue = $config['is_open_queue'] ?? 0;
$query_execute_time = $is_open_queue == 1 ? time() + 60 : time();
$list = model('cron')->getList([ [ 'execute_time', '<=', $query_execute_time ] ]);
$list = model('cron')->getList([['execute_time', '<=', $query_execute_time]]);
if (!empty($list)) {
foreach ($list as $k => $v) {
$event_res = checkQueue($v, function($params) {
$event_res = checkQueue($v, function ($params) {
//加入消息队列
$job_handler_classname = 'Cronexecute';
try {
if ($params[ 'execute_time' ] <= time()) {
if ($params['execute_time'] <= time()) {
Queue::push($job_handler_classname, $params);
} else {
Queue::later($params[ 'execute_time' ] - time(), $job_handler_classname, $params);
Queue::later($params['execute_time'] - time(), $job_handler_classname, $params);
}
} catch (\Exception $e) {
$res = $this->error($e->getMessage(), $e->getMessage());
}
return $res ?? $this->success();
}, function($params) {
}, function ($params) {
try {
$res = event($params[ 'event' ], [ 'relate_id' => $params[ 'relate_id' ] ]);
$res = event($params['event'], ['relate_id' => $params['relate_id']]);
} catch (\Exception $e) {
$res = $this->error($e->getMessage(), $e->getMessage());
}
$data_log = [
'name' => $params[ 'name' ],
'event' => $params[ 'event' ],
'relate_id' => $params[ 'relate_id' ],
'name' => $params['name'],
'event' => $params['event'],
'relate_id' => $params['relate_id'],
'message' => json_encode($res)
];
$this->addCronLog($data_log);
return $res;
});
//定义最新的执行时间或错误
$event_code = $event_res[ 'code' ] ?? 0;
$event_code = $event_res['code'] ?? 0;
if ($event_code < 0) {
Log::write($event_res);
continue;
}
//循环任务
if ($v[ 'type' ] == 2) {
$period = $v[ 'period' ] == 0 ? 1 : $v[ 'period' ];
switch ( $v[ 'period_type' ] ) {
if ($v['type'] == 2) {
$period = $v['period'] == 0 ? 1 : $v['period'];
switch ($v['period_type']) {
case 0://
$execute_time = $v[ 'execute_time' ] + $period * 60;
$execute_time = $v['execute_time'] + $period * 60;
break;
case 1://
$execute_time = strtotime('+' . $period . 'day', $v[ 'execute_time' ]);
$execute_time = strtotime('+' . $period . 'day', $v['execute_time']);
break;
case 2://
$execute_time = strtotime('+' . $period . 'week', $v[ 'execute_time' ]);
$execute_time = strtotime('+' . $period . 'week', $v['execute_time']);
break;
case 3://
$execute_time = strtotime('+' . $period . 'month', $v[ 'execute_time' ]);
$execute_time = strtotime('+' . $period . 'month', $v['execute_time']);
break;
}
model('cron')->update([ 'execute_time' => $execute_time ], [ [ 'id', '=', $v[ 'id' ] ] ]);
model('cron')->update(['execute_time' => $execute_time], [['id', '=', $v['id']]]);
} else {
model('cron')->delete([ [ 'id', '=', $v[ 'id' ] ] ]);
model('cron')->delete([['id', '=', $v['id']]]);
}
}
}
@ -146,7 +142,7 @@ class Cron extends BaseModel
public function addCronLog($data)
{
// 日常不需要添加,调试使用
$data[ 'execute_time' ] = time();
$data['execute_time'] = time();
model('cron_log')->add($data);
return $this->success();
}
@ -163,22 +159,22 @@ class Cron extends BaseModel
if (empty($cron_cache)) {
//todo 不存在缓存标识,并不视为任务停止
//创建缓存标识,当前时间填充
Cache::set('cron_cache', [ 'time' => $now_time, 'error' => '' ]);
Cache::set('cron_cache', ['time' => $now_time, 'error' => '']);
} else {
$time = $cron_cache[ 'time' ];
$error = $cron_cache[ 'error' ] ?? '';
$attempts = $cron_cache[ 'attempts' ] ?? 0;//尝试次数
if (!empty($error) || ( $now_time - $time ) > $diff) {
$time = $cron_cache['time'];
$error = $cron_cache['error'] ?? '';
$attempts = $cron_cache['attempts'] ?? 0;//尝试次数
if (!empty($error) || ($now_time - $time) > $diff) {
$message = '自动任务已停止';
if (!empty($error)) {
$message .= ',停止原因:' . $error;
} else {
$system_config_model = new \app\model\system\SystemConfig();
$config = $system_config_model->getSystemConfig()[ 'data' ] ?? [];
$is_open_queue = $config[ 'is_open_queue' ] ?? 0;
$config = $system_config_model->getSystemConfig()['data'] ?? [];
$is_open_queue = $config['is_open_queue'] ?? 0;
if (!$is_open_queue) {//如果不是消息队列的话,可以尝试异步调用一下
if ($attempts < 1) {
Cache::set('cron_cache', [ 'time' => $now_time, 'error' => '', 'attempts' => 1 ]);
Cache::set('cron_cache', ['time' => $now_time, 'error' => '', 'attempts' => 1]);
$url = url('cron/task/execute');
http($url, 1);
return $this->success();
@ -204,8 +200,8 @@ class Cron extends BaseModel
if (empty($cron_cache)) {
$cron_cache = [];
}
$cron_cache[ 'time' ] = time();
$cron_cache[ 'attempts' ] = 0;
$cron_cache['time'] = time();
$cron_cache['attempts'] = 0;
Cache::set('cron_cache', $cron_cache);
return $this->success();
}

View File

@ -15,6 +15,7 @@ namespace app\pay\controller;
use addon\aliapp\model\CloudPay;
use addon\aliapp\model\OpenPay;
use addon\futures\model\Forder;
use addon\futures\model\Futures;
use app\Controller;
use think\facade\Queue;
use think\Validate;
@ -25,27 +26,40 @@ class Test extends Controller
public function order(){
// $order=model('order')->getInfo(['order_id'=>2]);
$order=model('futures')->getList(['status'=>6]);
// var_dump($order);die;
// $res=event('OrderPay',$order);
// $order['relate_id']=254;
// $res=event('CronOrderClose',$order);
// var_dump($res);
$params=[
[
'relate_id'=>'264',
'name'=>'264',
'event'=>'Cronexecute',
],
[
'name'=>'265',
'event'=>'Cronexecute',
'relate_id'=>'265'
]
foreach ($order as $item){
$app=[
'relate_id'=>$item['order_id'],
'name'=>$item['order_id'],
'event'=>'CronOrderClose',
];
foreach ($params as $item){
var_dump($item);
Queue::push('Cronexecute', $item);
event('CronOrderClose',$app);
// Queue::push('Cronexecute', $app);
}
// $params=[
// [
// 'relate_id'=>'264',
// 'name'=>'264',
// 'event'=>'Cronexecute',
// ],
// [
// 'name'=>'265',
// 'event'=>'Cronexecute',
// 'relate_id'=>'265'
// ]
// ];
// foreach ($params as $item){
// var_dump($item);
// Queue::push('Cronexecute', $item);
// }
}
public function s(){
@ -53,9 +67,21 @@ class Test extends Controller
// $order=model('order')->getInfo(['order_id'=>258]);
$futures_model = new Futures();
$userModel = new User(1);
var_dump($userModel->buyBack());
// $res = $futures_model->orderClose(20);
// var_dump($res);
$order=model('order')->getInfo(['order_id'=>33]);
$order['relate_id']=33;
$res=event('CronOrderClose',$order);
var_dump($res);
// $userModel = new User(1);
// var_dump($userModel->buyBack());
// var_dump($res);
// var_dump(329*1/100);
@ -124,50 +150,5 @@ class Test extends Controller
// var_dump($allRow);die;
// }
public function ali(){
$info= Db::name('pay_shop')->select();
$CloudPay = new OpenPay();
$res = $CloudPay->query('','2022122900502000000060919247');
var_dump($res);die;
}
public function aa(){
$paydata=json_decode('{"line_type":"auth","app_type":"aliapp","site_id":"2","ag_site_id":"1","appid":"2021003131620226","appsecret":"","token":"","app_name":"","head_img":"","qrcode":"","account":"2088441422689415","alipay_public":"","private_key":"","app_auth_token":"202301BBb2dc039e58b248ae9c2c6c39bc83eE41","app_refresh_token":"202301BBbcb099fbbed0469abac3c02344bcdE41","app_original":"2088441422689415","original_values":{"app_auth_token":"202301BBb2dc039e58b248ae9c2c6c39bc83eE41","app_refresh_token":"202301BBbcb099fbbed0469abac3c02344bcdE41","auth_app_id":"2021003131620226","expires_in":31536000,"re_expires_in":32140800,"user_id":"2088441422689415"},"state":"2|minapp|1|1"}',true);
// var_dump($paydata);die;
$res=event('MiniappAuthInfo', $paydata);
var_dump($res);
}
public function b(){
$json=[
'notify_type' => 'open_app_auth_notify',
'charset' => 'UTF-8',
'biz_content' => '{"notify_context":{"trigger":"openhome","trigger_context":{"out_biz_no":"202301040000000008805896"}},"detail":{"app_auth_token":"202301BBc4311e1d4d094f2bb146267600195X84","user_id":"2088911181925841","re_expires_in":32140800,"auth_time":1673057100996,"app_refresh_token":"202301BB191270193a99454488e06fbc6368eX84","auth_app_id":"2021003173667904","app_id":"2021003167617037","expires_in":31536000,"app_auth_code":"ea1bfa68dfe3408aab7517686e7d8B84"},"error":{}}',
'notify_time' => '2023-01-08 10:34:49',
'sign' => 'BW6Ui/yFZ2RbKnI6trgg5ANRyv5CDy7rcpENurOKzqbDPZ4tVVmT6Q5QeaIofd7MG9E5xlwUn88rhrspz8IQdpJ9CVdAXilKbT6CPFKs4sNCJZu5yPqucceyi0SKLb9YUrpAfx+fR7RKFqJKNbpz8WUKlbKomIii7AYOt0vEqPXC9u3SWhdRxbFQy2NP52mo0Qr6ZPVSvHDSHd9EpQIVq2hqwVvoeGhs6UtoSiTHRErF9IIjOP/zvuXk9cj/YALpqa8t3oOC7+pePIJ9MSfzJOpzIKTvdISqPnX5Z/dULlEkmyGpDIT/gkd3TBMcaRb078vXydkY0RmMDuzUP5q9Rw==',
'auth_app_id' => '2021003173667904',
'app_id' => '2021003167617037',
'version' => '1.0',
'sign_type' => 'RSA2',
'notify_id' => '2023010700222100501062371438607977',
'status' => 'execute_auth'
];
$res= event('AliAuthNotify',$json);
var_dump($res);
}
public function n(){
$json='{"charset":"UTF-8","biz_content":"{\"smid\":\"2088420618732638\",\"memo\":\"商户进件完成\",\"external_id\":\"202212281644297838\",\"order_id\":\"2022122900502000000060919247\"}","utc_timestamp":"1673051330046","sign":"F4sGoWkEmQxSQbjjN8hKsal7Lba58UTqgdOVEz6x9ve2qqcqxzYmND\/v\/87RWrqB7r8hXxMxvyG\/bNUWIGtcxsfc4RYZjO83LY0pd7+3\/wxAtwfUNZyUbZDjdprk715KUHmPXvnjNNey+Ig96lF7Xa1B0YWNmvSmw2pYOrQ3v3Wd+vDu8fIQ4tNy+adnRzHylfxOmFO3mLVh7BQVBVZwhlHoZExHPInAcEhtczmygzM7UIsybQU5Tp5kbTs3iur7\/Wk0iMkgoMvqGTa\/UYpN6wVCLWq5gFqywrPERob3ka5vmgJB56ZqZZHCeaVKOX8tRvrb90+5GQUFf9HEC09kEA==","app_id":"2021003166659136","version":"1.1","sign_type":"RSA2","notify_id":"2023010600222230050034151455192412","msg_method":"ant.merchant.expand.indirect.zft.passed"}';
$json='{"charset":"UTF-8","biz_content":"{\"order_no\":\"2023010710002181800022005\",\"out_order_no\":\"202301040000000008805896\",\"pid\":\"2088911181925841\",\"min_app_id\":\"2021003173667904\",\"status\":\"AGREED\"}","utc_timestamp":"1673069254846","sign":"MEQVCJ9hwu71oa+\/yOTvq6NqwJWBMyVKiJ+Fmyu\/GKeVr0bfz2KOFxjaxEi4YfFaZRZBDiNs\/3jlHftUsZL4+RE9369bghDmo1bisdTuD3c5hPQXUS2igi\/nwcKKvnVSkWQl6G+WGy75o\/UKBOTKwd\/EA8MX7kmdGlI+uaocg2ZfFbEoM4r6i3xTA6yJ\/GtBFkibg4fSqrqVt+CewoP8AFGPjmQDVF6j6exXthKWW3eV\/xh30fUzWt24kUvadirfItYz1t0yjdG7Ny9Jm5mwoh0Bm8\/qa5QRxMojIC4q01PUVmaNWj5nSkQGrxrifbyS\/EqKEWMBhFKPORAy3kQzUw==","app_id":"2021003167617037","version":"1.1","sign_type":"RSA2","notify_id":"2023010700262100501056408716905123","msg_method":"alipay.open.mini.merchant.confirmed"}';
$json='{"notify_type":"open_app_auth_notify","charset":"UTF-8","biz_content":"{\"notify_context\":{\"trigger\":\"openhome\",\"trigger_context\":{\"out_biz_no\":\"202301040000000008805896\"}},\"detail\":{\"app_auth_token\":\"202301BBc4311e1d4d094f2bb146267600195X84\",\"user_id\":\"2088911181925841\",\"re_expires_in\":32140800,\"auth_time\":1673057100996,\"app_refresh_token\":\"202301BB191270193a99454488e06fbc6368eX84\",\"auth_app_id\":\"2021003173667904\",\"app_id\":\"2021003167617037\",\"expires_in\":31536000,\"app_auth_code\":\"ea1bfa68dfe3408aab7517686e7d8B84\"},\"error\":{}}","notify_time":"2023-01-07 13:32:12","sign":"Qoz0za4JgMvSwyqEhUVClrdtyNPX3X60aLgARA7llq7\/pCwjoJZJD1JPkC56wc3oTapO4rLSA1EalXnNT8OxSR9eUsG5YndIdM\/dIvyhAMYYPz7cdwq0cywY+Tu7VtbN6XYS\/4rz6PSuKsLAh+v2hYF6GDXmBvCDKIVwX1+DcD2g7i0G5T3tQ9H3AbC\/XIIloWzZhqKOGmSZMLHq47IL2Efcpcj3Fgehe5PqaERV3nLnALOcp5KDjJO7wSBl2Nh7kzTkASNcmEk9Y2Jslv08loO67De0GsmxYwMz0rCnKLsd8orxli52td\/IQiRDCDjLrE3iMPesx\/ZWMrBkrtBkog==","auth_app_id":"2021003173667904","app_id":"2021003167617037","version":"1.0","sign_type":"RSA2","notify_id":"2023010700222100501062371438607977","status":"execute_auth"}';
$json=json_decode($json,true);
event('AliAuthNotify',$json);
}
}

View File

@ -10,12 +10,12 @@
*/
return [
'name' => 'B2C_V4',
'title' => 'NiuShop单商户V5版',
'description' => 'NiuShop单商户V5版',
'title' => 'xxx',
'description' => 'xxxx',
'type' => 'system',
'status' => 1,
'author' => '',
'version' => '5.1.1',
'version_no' => '520221115001',
'content' => 'NiuShop单商户V5版'
'content' => 'xxx'
];