getLegumesPrice(); // 获取当前页数据 有效记录、已获取积分低于订单金额 $where = [ ['status', 'in', [0,1]] ]; if(count($ids) > 0) $where[] = ['id', 'in', $ids]; else $where[] = ['', 'exp', Db::raw('get_integral < order_money')]; $field = 'id,(order_money - refund_order_money) as order_money,(get_legumes - refund_get_legumes) as get_legumes,get_integral,member_id'; $result = model('commission_legumes_log')->pageList($where,$field,'',$page,$limit); $count = $result['count'] ?? 0; $list = $result['list'] ?? []; if(count($list) <= 0) throw new \Exception('无处理数据!'); // 循环处理 $updateData = []; $insertData = []; foreach($list as $item){ // 计算最新本订单商品 总释放积分;总释放积分不能超过订单金额 $getIntegral = (float)sprintf("%.2f",$item['get_legumes'] * $legumesPrice); $resultGetIntegral = $getIntegral >= $item['order_money'] ? $item['order_money'] : $getIntegral; // 修改信息记录 $updateData[] = [ 'id' => $item['id'], 'get_integral' => $resultGetIntegral ]; // 增加释放记录 仅存在变更数量时记录 $changeQuantity = (float)sprintf("%.2f",$resultGetIntegral - $item['get_integral']); if($changeQuantity > 0){ $insertData[] = [ 'member_id' => $item['member_id'], 'legumes_log_id' => $item['id'], 'change_front' => $item['get_integral'], 'change_quantity' => (float)sprintf("%.2f",$resultGetIntegral - $item['get_integral']), 'change_after' => $resultGetIntegral, ]; } } // 修改 $newBaseModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id'])); $newBaseModel->saveAll($updateData); // 增加记录 if(count($insertData) > 0) model('commission_legumes_release_log')->addList($insertData); // 判断:是否存在下一页 $currentLimit = $page * $limit; if($currentLimit < $count){ $data['page'] = $page + 1; Queue::push(ComputeIntegralJob::class,$data); } Db::commit(); } catch(\Exception $e){ Db::rollback(); trace($e->getMessage(), '平台抽成 - 全平台豆豆转积分 - 失败'); } $job->delete(); } public function failed($data){ trace($data, '平台抽成 - 全平台豆豆转积分 - 失败(failed)'); } }