|
|
@@ -9,6 +9,7 @@ use app\common\model\UserWelfare;
|
|
|
use app\common\model\ProductPopular;
|
|
|
use app\common\model\ProductOrder;
|
|
|
use app\common\model\UserModel;
|
|
|
+use think\Loader;
|
|
|
use think\Db;
|
|
|
use think\Log;
|
|
|
use Exception;
|
|
|
@@ -49,15 +50,8 @@ class WelfareLoginc
|
|
|
*/
|
|
|
public static function getUserRwaProductNum(int $productId, int $rwa_num, $mod, $num): int
|
|
|
{
|
|
|
- //读取当日新增数据
|
|
|
- $list = ProductOrder::where('product_id', $productId)
|
|
|
- ->whereIn('status', [ProductOrder::Paid, ProductOrder::Transferred, ProductOrder::Freeze])
|
|
|
- //->where('popular_price', '>', config('min_rwa_price'))
|
|
|
- ->field('user_id,sum(num) as total_num')
|
|
|
- ->group('user_id')
|
|
|
- ->field('user_id,count(num) as total_num')
|
|
|
- ->group('user_id')
|
|
|
- ->having('total_num>='.$rwa_num)->select();
|
|
|
+ //读取当前新增数据
|
|
|
+ $list = ProductOrder::getUserOrderByProductId($productId, $rwa_num);
|
|
|
if(empty($list)) return 0;
|
|
|
$total = 0; //总数量
|
|
|
if($mod == 1 && $num > 0){
|
|
|
@@ -88,12 +82,8 @@ class WelfareLoginc
|
|
|
$total = 0; //总数量
|
|
|
// 使用bcdiv函数进行高精度除法运算,$num除以100,保留两位小数
|
|
|
$div = bcdiv($num, 100, 2);
|
|
|
- $list = ProductOrder::whereIn('status', [ProductOrder::Paid, ProductOrder::Transferred, ProductOrder::Freeze])
|
|
|
- ->where('product_id', $rwaProductId)
|
|
|
- //->where('popular_price', '>', config('min_rwa_price'))
|
|
|
- ->group('user_id')->having('total_num>='.$rwa_num)
|
|
|
- ->field('id,user_id,count(num) as total_num')
|
|
|
- ->select();
|
|
|
+ $list = ProductOrder::getUserOrderByProductId($rwaProductId, $rwa_num);
|
|
|
+
|
|
|
$user = new UserModel();
|
|
|
foreach($list as $order){
|
|
|
//根据$mod的值决定是否需要对用户的rwa_num进行乘以$div的运算
|
|
|
@@ -108,6 +98,28 @@ class WelfareLoginc
|
|
|
return $total;
|
|
|
}
|
|
|
|
|
|
+ //合成订单
|
|
|
+ public static function setSynthesisOrder($synthesis, $productId, $num, $uid):array
|
|
|
+ {
|
|
|
+ $result = array();
|
|
|
+ $model = Loader::model('ProductOrder');
|
|
|
+ foreach ($productId as $key => $item) {
|
|
|
+
|
|
|
+ //获取需求数量
|
|
|
+ if(!isset($synthesis[$key.'_num'])) throw new Exception(__("参数有误,无可用产品"));
|
|
|
+ //判断持有数量足够
|
|
|
+ $total_num = $synthesis[$key.'_num'] * $num;
|
|
|
+
|
|
|
+ $order_arr = $model::getUserOrderByProductNum($uid, $item, $total_num);
|
|
|
+ if($total_num != count($order_arr)) throw new Exception(__("材料不足"));
|
|
|
+
|
|
|
+ //关闭持有订单
|
|
|
+ $model::whereIn('id', $order_arr)->setField('status', $model::Closure);
|
|
|
+ $result[$key][] = ['combine'=>$item, 'new_order'=>$order_arr];
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 设置用户产品订单
|