|
|
@@ -0,0 +1,96 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\logic;
|
|
|
+
|
|
|
+use app\common\enum\GoodsEnum;
|
|
|
+use app\common\enum\PayEnum;
|
|
|
+use app\common\enum\WorkEnum;
|
|
|
+use app\common\logic\BaseLogic;
|
|
|
+use app\common\model\coupon\UserCoupon;
|
|
|
+use app\common\model\dict\DictData;
|
|
|
+use app\common\model\goods\Goods;
|
|
|
+use app\common\model\master_worker\MasterWorker;
|
|
|
+use app\common\model\orders\RechargeOrder;
|
|
|
+use app\common\model\property\PropertyCommission;
|
|
|
+use app\common\model\property\PropertyHead;
|
|
|
+use app\common\model\property\PropertyOrder;
|
|
|
+use app\common\model\property\PropertySurplusLog;
|
|
|
+use app\common\model\property\PropertyUser;
|
|
|
+use app\common\model\recharge\OrderGoods;
|
|
|
+use app\common\model\works\ServiceWork;
|
|
|
+use app\workerapi\logic\ServiceWorkLogLogic;
|
|
|
+use think\Exception;
|
|
|
+use think\facade\Db;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 物业分成
|
|
|
+ * Class PropertyCommissionLogic
|
|
|
+ * @package app\api\logic
|
|
|
+ */
|
|
|
+class PropertyCommissionLogic extends BaseLogic
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认服务完成物业分成
|
|
|
+ * @param $params
|
|
|
+ * @return false|true
|
|
|
+ */
|
|
|
+ public static function commissionSurplus($params)
|
|
|
+ {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $work_id = \app\common\model\recharge\RechargeOrder::where([
|
|
|
+ 'order_type' => 0,
|
|
|
+ 'user_id' => $params['user_id'],
|
|
|
+ 'sn'=>$params['sn']
|
|
|
+ ])->value('work_id');
|
|
|
+ if(empty($work_id)){
|
|
|
+ throw new Exception('订单不存在');
|
|
|
+ }
|
|
|
+ // 判断工单是否用户已完结
|
|
|
+ $service_work = ServiceWork::find($work_id);
|
|
|
+ if($service_work->user_confirm_status!=5){
|
|
|
+ throw new Exception('未完结订单,无法完成分成');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 以工单 结算金额 为基准,计算分成金额
|
|
|
+ $work_amount = $service_work->work_amount;
|
|
|
+ $propertyUserId = PropertyUser::where('user_id',$params['user_id'])->value('id');
|
|
|
+ $propertyOrderInfo = PropertyOrder::where(['property_user_id' => $propertyUserId,'order_status' => 1,'work_id'=>$work_id])->findOrEmpty()->toArray();
|
|
|
+ //计算分成金额
|
|
|
+ $ratio = PropertyHead::where('id',$propertyOrderInfo['property_head_id'])->value('ratio');
|
|
|
+ $commission_amount = number_format($work_amount * ($ratio/100),2,'.','');
|
|
|
+ // 添加分成记录
|
|
|
+ $propertyCommissionInfo = PropertyCommission::create([
|
|
|
+ 'property_head_id' => $propertyOrderInfo['property_head_id'],
|
|
|
+ 'property_user_id' => $propertyUserId,
|
|
|
+ 'property_order_id' => $propertyOrderInfo['id'],
|
|
|
+ 'work_id' => $work_id,
|
|
|
+ 'order_amount' => $work_amount,
|
|
|
+ 'ratio' => $ratio,
|
|
|
+ 'commission_amount' => $commission_amount,
|
|
|
+ ]);
|
|
|
+ // 更新物业收益/订单状态已完结
|
|
|
+ PropertyHead::where(['id' => $propertyOrderInfo['property_head_id']])->update([
|
|
|
+ 'all_profit_amount' => Db::raw('all_profit_amount+'.$commission_amount),
|
|
|
+ 'surplus_profit_amount' => Db::raw('surplus_profit_amount+'.$commission_amount)
|
|
|
+ ]);
|
|
|
+ PropertyOrder::where(['id' => $propertyOrderInfo['id']])->update(['order_status' => 3]);
|
|
|
+ // 进出账记录
|
|
|
+ PropertySurplusLog::create([
|
|
|
+ 'in_out' => 1,
|
|
|
+ 'property_commission_id' => $propertyCommissionInfo['id'],
|
|
|
+ 'amount' => $commission_amount,
|
|
|
+ 'status' => 1,
|
|
|
+ 'remark' => '订单完成,分成金额入账'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ return true;
|
|
|
+ }catch (\Exception $e) {
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|