|
@@ -9,6 +9,7 @@ namespace app\models\store;
|
|
|
|
|
|
use app\admin\model\system\ShippingTemplatesFree;
|
|
|
use app\admin\model\system\ShippingTemplatesRegion;
|
|
|
+use app\admin\model\user\UserProduct;
|
|
|
use crmeb\basic\BaseModel;
|
|
|
use think\db\exception\DataNotFoundException;
|
|
|
use think\db\exception\DbException;
|
|
@@ -770,9 +771,7 @@ class StoreOrder extends BaseModel
|
|
|
{
|
|
|
$order = self::where('order_id', $orderId)->find();
|
|
|
$productId = StoreProduct::where('is_upgrade', 1)->column('id');
|
|
|
- if (count(StoreOrderCartInfo::where('oid', $order['id'])->where('product_id', 'in', $productId)->select()) > 0){
|
|
|
- self::reward($order, $productId);
|
|
|
- }
|
|
|
+ self::reward($order, 1);
|
|
|
$resPink = true;
|
|
|
$res1 = self::where('order_id', $orderId)->update(['paid' => 1, 'pay_type' => $paytype, 'pay_time' => time(), 'is_del' => 0, 'is_system_del' => 0, 'mark' => '']);//订单改为支付
|
|
|
if ($order->combination_id && $res1 && !$order->refund_status) $resPink = StorePink::createPink($order);//创建拼团
|
|
@@ -787,12 +786,19 @@ class StoreOrder extends BaseModel
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static function reward($order, $productId)
|
|
|
+ public static function reward($order,$type)
|
|
|
{
|
|
|
- $list = StoreOrderCartInfo::where('oid', $order['id'])->where('product_id', 'in', $productId)->select()->toArray();
|
|
|
+ $list = StoreOrderCartInfo::where('oid', $order['id'])->select();
|
|
|
$user = User::where('uid', $order['uid'])->find();
|
|
|
$user1 = User::where('uid', $user['spread_uid'])->find();
|
|
|
$user2 = User::where('uid', $user1['spread_uid'])->find();
|
|
|
+ if ($type == 1){
|
|
|
+ $str = '购买';
|
|
|
+ }elseif ($type == 2){
|
|
|
+ $str = '进货';
|
|
|
+ }elseif ($type ==3){
|
|
|
+ $str = '店家购买';
|
|
|
+ }
|
|
|
foreach ($list as $item){
|
|
|
$product = StoreProduct::where('id', $item['product_id'])->find();
|
|
|
$num = $item['cart_info']['cart_num'];
|
|
@@ -803,19 +809,40 @@ class StoreOrder extends BaseModel
|
|
|
if ($user1){
|
|
|
User::where('uid', $user['spread_uid'])->inc('brokerage_price', $price1+$price2)->update();
|
|
|
$user1['brokerage_price'] += $price1;
|
|
|
- UserBill::income('直推奖励', $user1['uid'], 'now_money', 'push', $price1, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].'购买商品数量'.$num);
|
|
|
+ UserBill::income('直推奖励', $user1['uid'], 'now_money', 'push', $price1, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
$user1['brokerage_price'] += $price2;
|
|
|
- UserBill::income('直推销售提成', $user1['uid'], 'now_money', 'sale', $price2, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].'购买商品数量'.$num);
|
|
|
+ UserBill::income('直推销售提成', $user1['uid'], 'now_money', 'sale', $price2, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
}
|
|
|
|
|
|
if ($user2){
|
|
|
User::where('uid', $user1['spread_uid'])->inc('brokerage_price', $price3+$price4)->update();
|
|
|
$user2['brokerage_price'] += $price3;
|
|
|
- UserBill::income('间推奖励', $user2['uid'], 'now_money', 'jt_push', $price3, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].'购买商品数量'.$num);
|
|
|
+ UserBill::income('间推奖励', $user2['uid'], 'now_money', 'jt_push', $price3, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].','.$str.'编号'.$item['product_id'].'数量'.$num);
|
|
|
$user2['brokerage_price'] += $price4;
|
|
|
- UserBill::income('间推销售提成', $user2['uid'], 'now_money', 'zt_sale', $price4, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].'购买商品数量'.$num);
|
|
|
+ UserBill::income('间推销售提成', $user2['uid'], 'now_money', 'zt_sale', $price4, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
+ }
|
|
|
+ if ($type == 2){
|
|
|
+ $user_product = UserProduct::where('uid', $order['uid'])->where('product_id', $item['product_id'])->find();
|
|
|
+ if (!$user_product){
|
|
|
+ UserProduct::create([
|
|
|
+ 'uid' => $order['uid'],
|
|
|
+ 'product_id' => $item['product_id'],
|
|
|
+ 'number' => $num
|
|
|
+ ]);
|
|
|
+ }else{
|
|
|
+ $user_product['number'] += $num;
|
|
|
+ $user_product->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($type == 3){
|
|
|
+ $user_product = UserProduct::where('uid', $order['consignor'])->where('product_id', $item['product_id'])->find();
|
|
|
+ $user_product['number'] -= $num;
|
|
|
+ $user_product->save();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -1141,12 +1168,19 @@ class StoreOrder extends BaseModel
|
|
|
* @throws ModelNotFoundException
|
|
|
* @throws \think\exception\DbException
|
|
|
*/
|
|
|
- public static function getUserOrderList($uid, $status = '', $page = 0, $limit = 8)
|
|
|
+ public static function getUserOrderList($uid, $status = '', $page = 0, $limit = 8, $purchase = '')
|
|
|
{
|
|
|
+ if ($purchase == 1){
|
|
|
+ $where[] = ['purchase', '=', 1];
|
|
|
+ }else{
|
|
|
+ $where[] = ['purchase', '<>', 1];
|
|
|
+ }
|
|
|
if ($page) $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid', $uid)
|
|
|
+ ->where($where)
|
|
|
->field('add_time,seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,pink_id,delivery_type,is_del,shipping_type')
|
|
|
->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
|
|
|
else $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid', $uid)
|
|
|
+ ->where($where)
|
|
|
->field('add_time,seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,pink_id,delivery_type,is_del,shipping_type')
|
|
|
->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
|
|
|
foreach ($list as $k => $order) {
|
|
@@ -1305,13 +1339,13 @@ class StoreOrder extends BaseModel
|
|
|
* @param string $search 订单号
|
|
|
* @return array
|
|
|
* */
|
|
|
- public static function getUserOrderSearchList($uid, $type, $page, $limit, $search)
|
|
|
+ public static function getUserOrderSearchList($uid, $type, $page, $limit, $search, $purchase = '')
|
|
|
{
|
|
|
if ($search) {
|
|
|
$order = self::searchUserOrder($uid, $search) ?: [];
|
|
|
$list = $order == false ? [] : [$order];
|
|
|
} else {
|
|
|
- $list = self::getUserOrderList($uid, $type, $page, $limit);
|
|
|
+ $list = self::getUserOrderList($uid, $type, $page, $limit, $purchase);
|
|
|
}
|
|
|
foreach ($list as $k => $order) {
|
|
|
$list[$k] = self::tidyOrder($order, true);
|
|
@@ -1382,24 +1416,32 @@ class StoreOrder extends BaseModel
|
|
|
* @param $uid
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public static function getOrderData($uid)
|
|
|
+ public static function getOrderData($uid, $purchase = '')
|
|
|
{
|
|
|
+ if ($purchase == 1){
|
|
|
+ $where[] = ['purchase', '=', 1];
|
|
|
+ }else{
|
|
|
+ $where[] = ['purchase', '<>', 1];
|
|
|
+ }
|
|
|
+
|
|
|
//订单支付没有退款 数量
|
|
|
- $data['order_count'] = self::where('is_del', 0)->where('paid', 1)->where('uid', $uid)->where('refund_status', 0)->count();
|
|
|
+ $data['order_count'] = self::where('is_del', 0)->where('paid', 1)->where($where)->where('uid', $uid)->where('refund_status', 0)->count();
|
|
|
//订单支付没有退款 支付总金额
|
|
|
- $data['sum_price'] = self::where('is_del', 0)->where('paid', 1)->where('uid', $uid)->where('refund_status', 0)->sum('pay_price');
|
|
|
+ $data['sum_price'] = self::where('is_del', 0)->where('paid', 1)->where($where)->where('uid', $uid)->where('refund_status', 0)->sum('pay_price');
|
|
|
//订单待支付 数量
|
|
|
- $data['unpaid_count'] = self::statusByWhere(0, $uid)->where('is_del', 0)->where('uid', $uid)->count();
|
|
|
+ $data['unpaid_count'] = self::statusByWhere(0, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
|
|
|
//订单待发货 数量
|
|
|
- $data['unshipped_count'] = self::statusByWhere(1, $uid)->where('is_del', 0)->where('uid', $uid)->count();
|
|
|
+ $data['unshipped_count'] = self::statusByWhere(1, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
|
|
|
//订单待收货 数量
|
|
|
- $data['received_count'] = self::statusByWhere(2, $uid)->where('is_del', 0)->where('uid', $uid)->count();
|
|
|
+ $data['received_count'] = self::statusByWhere(2, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
|
|
|
//订单待评价 数量
|
|
|
- $data['evaluated_count'] = self::statusByWhere(3, $uid)->where('is_del', 0)->where('uid', $uid)->count();
|
|
|
+ $data['evaluated_count'] = self::statusByWhere(3, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
|
|
|
//订单已完成 数量
|
|
|
- $data['complete_count'] = self::statusByWhere(4, $uid)->where('is_del', 0)->where('uid', $uid)->count();
|
|
|
+ $data['complete_count'] = self::statusByWhere(4, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
|
|
|
//订单退款
|
|
|
- $data['refund_count'] = self::statusByWhere(-1, $uid)->where('is_del', 0)->where('uid', $uid)->count();
|
|
|
+ $data['refund_count'] = self::statusByWhere(-1, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
|
|
|
+
|
|
|
+
|
|
|
return $data;
|
|
|
}
|
|
|
|