|
|
@@ -5,13 +5,16 @@ use app\adminapi\logic\property\PropertyUserLogic;
|
|
|
use app\common\logic\BaseLogic;
|
|
|
use app\common\model\coupon\CouponGoods;
|
|
|
use app\common\model\coupon\CouponRules;
|
|
|
+use app\common\model\coupon\UserCoupon;
|
|
|
use app\common\model\goods\Goods;
|
|
|
use app\common\model\goods_category\GoodsCategory;
|
|
|
use app\common\model\property\PropertyActivity;
|
|
|
use app\common\model\property\PropertyHead;
|
|
|
use app\common\model\property\PropertyOrder;
|
|
|
use app\common\model\property\PropertyUser;
|
|
|
+use app\common\model\recharge\RechargeOrder;
|
|
|
use app\common\model\user\User;
|
|
|
+use app\common\model\works\ServiceWork;
|
|
|
use think\facade\Db;
|
|
|
use think\facade\Log;
|
|
|
|
|
|
@@ -243,4 +246,55 @@ class ActivityLogic extends BaseLogic
|
|
|
return $ids??[0];
|
|
|
}
|
|
|
|
|
|
+ /** 优惠券逆向为活动工单+代理订单
|
|
|
+ * @param $params
|
|
|
+ * @param $serviceOrder
|
|
|
+ * @return true
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ public static function ReverseCouponToActivity($params){
|
|
|
+ try{
|
|
|
+ $serviceOrder = ServiceWork::where('id',$params['id'])->where('property_activity_id',0)->findOrEmpty();
|
|
|
+ if($serviceOrder->isEmpty()){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 查询优惠券id
|
|
|
+ $coupon_ids = RechargeOrder::where('work_id',$params['id'])->where('coupon_id','>',0)->column('coupon_id');
|
|
|
+ if(empty($coupon_ids)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $property_activity_id = UserCoupon::where('user_id',$serviceOrder->user_id)->whereIn('coupon_id',$coupon_ids)->where('property_activity_id','>',0)->value('property_activity_id');
|
|
|
+ if(empty($property_activity_id)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $propertyActivity = PropertyActivity::findOrEmpty($property_activity_id);
|
|
|
+ if($propertyActivity->isEmpty()){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $user_info = User::findOrEmpty($serviceOrder->user_id);
|
|
|
+ $propertyOrder = PropertyOrder::where('work_id',$serviceOrder->id)->findOrEmpty();
|
|
|
+ if($propertyOrder->isEmpty()){
|
|
|
+ // 生成代理单
|
|
|
+ // householder_mobile property_head_id householder_name address remark order_status work_id
|
|
|
+ $result = PropertyOrderLogic::add([
|
|
|
+ 'property_head_id' => $propertyActivity['property_head_id'],
|
|
|
+ 'householder_mobile' => $user_info['mobile'],
|
|
|
+ 'householder_name' => $user_info['real_name'],
|
|
|
+ 'address' => $serviceOrder->address,
|
|
|
+ 'remark' => '优惠券逆向活动工单',
|
|
|
+ 'order_status' => 3,
|
|
|
+ 'work_id' => $serviceOrder->id,
|
|
|
+ ]);
|
|
|
+ if($result === false){
|
|
|
+ throw new \Exception('优惠券逆向活动工单失败');
|
|
|
+ }
|
|
|
+ $serviceOrder->property_activity_id = $property_activity_id;
|
|
|
+ $serviceOrder->save();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }catch(\Exception $e){
|
|
|
+ throw new \Exception($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|