|
@@ -8,82 +8,109 @@ use app\common\enum\WorkEnum;
|
|
|
use app\common\model\equity\UserEquity;
|
|
use app\common\model\equity\UserEquity;
|
|
|
use app\common\model\works\ServiceWork;
|
|
use app\common\model\works\ServiceWork;
|
|
|
use app\common\model\equity\UserEquityLog;
|
|
use app\common\model\equity\UserEquityLog;
|
|
|
|
|
+use app\common\model\orders\RechargeOrder;
|
|
|
|
|
+use app\common\model\group_activity\GroupOrder;
|
|
|
use app\common\model\group_activity\GroupUserOrder;
|
|
use app\common\model\group_activity\GroupUserOrder;
|
|
|
|
|
|
|
|
class AddServiceWorkJob
|
|
class AddServiceWorkJob
|
|
|
{
|
|
{
|
|
|
public function fire(Job $job, $data)
|
|
public function fire(Job $job, $data)
|
|
|
{
|
|
{
|
|
|
|
|
+ $group_order_id = $data['id'];//拼团订单ID
|
|
|
|
|
+ $goods = [];
|
|
|
try {
|
|
try {
|
|
|
- Log::info('执行队列任务:'.json_encode($data));
|
|
|
|
|
-
|
|
|
|
|
//查询拼团用户订单
|
|
//查询拼团用户订单
|
|
|
$userOrder = GroupUserOrder::alias('a')->leftJoin('user b','a.user_id=b.id')
|
|
$userOrder = GroupUserOrder::alias('a')->leftJoin('user b','a.user_id=b.id')
|
|
|
- ->where('group_order_id', $data['id'])
|
|
|
|
|
|
|
+ ->where('group_order_id', $group_order_id)
|
|
|
->where('pay_status', 1)
|
|
->where('pay_status', 1)
|
|
|
->where('refund_status', 0)
|
|
->where('refund_status', 0)
|
|
|
->field('a.*,b.mobile')
|
|
->field('a.*,b.mobile')
|
|
|
->select()
|
|
->select()
|
|
|
->toArray();
|
|
->toArray();
|
|
|
- try {
|
|
|
|
|
- Db::startTrans();
|
|
|
|
|
- foreach ($userOrder as $k => $item) {
|
|
|
|
|
- if (empty($goods)) {
|
|
|
|
|
- $goods = UserEquity::alias('a')->leftJoin('goods b','a.goods_id=b.id')
|
|
|
|
|
- ->where('a.id', $item['user_equity_id'])
|
|
|
|
|
- ->field('b.goods_name,b.category_type,b.goods_category_ids,b.goods_category_id,b.base_service_fee')
|
|
|
|
|
- ->find();
|
|
|
|
|
- }
|
|
|
|
|
- //生成服务工单
|
|
|
|
|
- $work_data = [
|
|
|
|
|
- 'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
|
|
|
|
|
- 'real_name' => '',
|
|
|
|
|
- 'mobile' => $item['mobile'],
|
|
|
|
|
- 'address' => $item['area'].$item['address'],
|
|
|
|
|
- 'province' => 0,
|
|
|
|
|
- 'city' => 0,
|
|
|
|
|
- 'area_name' => '',
|
|
|
|
|
- 'title' => $goods['goods_name'],
|
|
|
|
|
- 'category_type' => $goods['category_type'],
|
|
|
|
|
- 'goods_category_ids' => $goods['goods_category_ids'],
|
|
|
|
|
- 'goods_category_id' => $goods['goods_category_id'],
|
|
|
|
|
- 'base_service_fee' => $goods['base_service_fee'],
|
|
|
|
|
- 'service_fee' => $item['paid_amount'],
|
|
|
|
|
- 'work_pay_status'=>WorkEnum::IS_PAY_STATUS,
|
|
|
|
|
- 'appointment_time' => time(),
|
|
|
|
|
- 'user_id'=>$item['user_id'],
|
|
|
|
|
- 'lon'=>'',
|
|
|
|
|
- 'lat'=>'',
|
|
|
|
|
- 'property_activity_id'=>0,
|
|
|
|
|
- 'user_equity_id'=>0,
|
|
|
|
|
- 'third_type'=>1,
|
|
|
|
|
- 'work_total'=>$item['paid_amount'],
|
|
|
|
|
- 'work_amount'=>$item['paid_amount'],
|
|
|
|
|
- 'work_status' => 5,
|
|
|
|
|
- 'user_confirm_status' => 3,
|
|
|
|
|
- 'service_status' => 1,
|
|
|
|
|
- 'master_worker_id' => 7,
|
|
|
|
|
- 'remark' => '拼团单:'.$item['id'],
|
|
|
|
|
- 'user_equity_id' => $item['user_equity_id'],
|
|
|
|
|
- 'group_order_id' => $item['id'],
|
|
|
|
|
- ];
|
|
|
|
|
- ServiceWork::create($work_data);
|
|
|
|
|
-
|
|
|
|
|
- UserEquityLog::create([
|
|
|
|
|
- 'user_id' => $item['user_id'],
|
|
|
|
|
- 'number' => 1,
|
|
|
|
|
- 'user_equity_id' => $item['user_equity_id'],
|
|
|
|
|
- 'create_time' => time(),
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($userOrder)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ foreach ($userOrder as $k => $item) {
|
|
|
|
|
+ if (empty($goods)) {
|
|
|
|
|
+ $goods = UserEquity::alias('a')->leftJoin('goods b','a.goods_id=b.id')
|
|
|
|
|
+ ->where('a.id', $item['user_equity_id'])
|
|
|
|
|
+ ->field('a.number,b.goods_name,b.category_type,b.goods_category_ids,b.goods_category_id,b.base_service_fee')
|
|
|
|
|
+ ->findOrEmpty()
|
|
|
|
|
+ ->toArray();
|
|
|
}
|
|
}
|
|
|
- Db::commit();
|
|
|
|
|
- } catch (\Exception $e) {
|
|
|
|
|
- Db::rollback();
|
|
|
|
|
- Log::error('执行队列任务失败:'.$e->getMessage());
|
|
|
|
|
|
|
+ //生成服务工单
|
|
|
|
|
+ $work_data = [
|
|
|
|
|
+ 'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
|
|
|
|
|
+ 'real_name' => '',
|
|
|
|
|
+ 'mobile' => $item['mobile'],
|
|
|
|
|
+ 'address' => $item['area'].$item['address'],
|
|
|
|
|
+ 'province' => 0,
|
|
|
|
|
+ 'city' => 0,
|
|
|
|
|
+ 'area_name' => '',
|
|
|
|
|
+ 'title' => $goods['goods_name'],
|
|
|
|
|
+ 'category_type' => $goods['category_type'],
|
|
|
|
|
+ 'goods_category_ids' => $goods['goods_category_ids'],
|
|
|
|
|
+ 'goods_category_id' => $goods['goods_category_id'],
|
|
|
|
|
+ 'base_service_fee' => $goods['base_service_fee'],
|
|
|
|
|
+ 'service_fee' => $item['paid_amount'],
|
|
|
|
|
+ 'work_pay_status'=>WorkEnum::IS_PAY_STATUS,
|
|
|
|
|
+ 'appointment_time' => time(),
|
|
|
|
|
+ 'dispatch_time' => time(),
|
|
|
|
|
+ 'receive_time' => time(),
|
|
|
|
|
+ 'user_id'=>$item['user_id'],
|
|
|
|
|
+ 'lon'=>'',
|
|
|
|
|
+ 'lat'=>'',
|
|
|
|
|
+ 'property_activity_id'=>0,
|
|
|
|
|
+ 'user_equity_id'=>0,
|
|
|
|
|
+ 'third_type'=>1,
|
|
|
|
|
+ 'work_total'=>$item['paid_amount'],
|
|
|
|
|
+ 'work_status' => 5,
|
|
|
|
|
+ 'user_confirm_status' => 3,
|
|
|
|
|
+ 'service_status' => 1,
|
|
|
|
|
+ 'master_worker_id' => 7,
|
|
|
|
|
+ 'remark' => '拼团单:'.$item['id'],
|
|
|
|
|
+ 'user_equity_id' => $item['user_equity_id'],
|
|
|
|
|
+ 'group_order_id' => $item['id'],
|
|
|
|
|
+ 'third_type' => 0,
|
|
|
|
|
+ ];
|
|
|
|
|
+ $service_work = ServiceWork::create($work_data);
|
|
|
|
|
+
|
|
|
|
|
+ //生成客户订单
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'work_id'=> $service_work['id'],
|
|
|
|
|
+ 'sn' => generate_sn(RechargeOrder::class, 'sn'),
|
|
|
|
|
+ 'order_type'=>0,//服务订单
|
|
|
|
|
+ 'order_terminal' => $item['order_terminal'],
|
|
|
|
|
+ 'user_id' => $item['user_id'],
|
|
|
|
|
+ 'pay_status' => $item['pay_status'],
|
|
|
|
|
+ 'pay_way' => $item['pay_way'],
|
|
|
|
|
+ 'order_total' => 0,
|
|
|
|
|
+ 'order_amount' => 0,
|
|
|
|
|
+ ];
|
|
|
|
|
+ $order = RechargeOrder::create($data);
|
|
|
|
|
+ //更新用户的权益卡剩余次数
|
|
|
|
|
+ UserEquity::where('id', $item['user_equity_id'])->update(['number' => 0, 'update_time' => time()]);
|
|
|
|
|
+
|
|
|
|
|
+ //记录用户的权益卡使用记录
|
|
|
|
|
+ UserEquityLog::create([
|
|
|
|
|
+ 'user_id' => $item['user_id'],
|
|
|
|
|
+ 'number' => $goods['number'],
|
|
|
|
|
+ 'user_equity_id' => $item['user_equity_id'],
|
|
|
|
|
+ 'create_time' => time(),
|
|
|
|
|
+ ]);
|
|
|
}
|
|
}
|
|
|
- // 任务执行成功,删除任务
|
|
|
|
|
|
|
+
|
|
|
|
|
+ GroupOrder::where('id', $group_order_id)->update(['work_status' => 2]);
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+ // 任务执行完毕后删除任务
|
|
|
$job->delete();
|
|
$job->delete();
|
|
|
|
|
+ return true;
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ Log::write("拼团订单批量生成服务工单异常:".$e->getMessage());
|
|
|
// 任务执行失败,重试任务
|
|
// 任务执行失败,重试任务
|
|
|
if ($job->attempts() > 3) {
|
|
if ($job->attempts() > 3) {
|
|
|
// 超过最大重试次数,删除任务
|
|
// 超过最大重试次数,删除任务
|
|
@@ -91,6 +118,7 @@ class AddServiceWorkJob
|
|
|
} else {
|
|
} else {
|
|
|
$job->release(10); // 10 秒后重试
|
|
$job->release(10); // 10 秒后重试
|
|
|
}
|
|
}
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|