|
@@ -9,6 +9,7 @@ namespace app\models\store;
|
|
|
|
|
|
use app\admin\model\system\ShippingTemplatesFree;
|
|
|
use app\admin\model\system\ShippingTemplatesRegion;
|
|
|
+use app\admin\model\system\SystemAdmin;
|
|
|
use app\admin\model\system\SystemStorePoint;
|
|
|
use crmeb\basic\BaseModel;
|
|
|
use think\db\exception\DataNotFoundException;
|
|
@@ -19,6 +20,7 @@ use crmeb\traits\ModelTrait;
|
|
|
use think\facade\Log;
|
|
|
use app\models\system\SystemStore;
|
|
|
use app\models\routine\RoutineTemplate;
|
|
|
+use think\Model;
|
|
|
use app\models\user\{User, UserAddress, UserBill, UserSpread, WechatUser};
|
|
|
use crmeb\services\{MiniProgramService,
|
|
|
OtherSMSService,
|
|
@@ -2259,4 +2261,72 @@ class StoreOrder extends BaseModel
|
|
|
return compact('list', 'count');
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理奖励
|
|
|
+ */
|
|
|
+ public static function treatmentAward($order_id)
|
|
|
+ {
|
|
|
+ $order = StoreOrder::get($order_id);
|
|
|
+ if (!$order) return self::setErrorInfo('找不到订单');
|
|
|
+ if (!$order['transaction_id']) return true;
|
|
|
+ $store = SystemStorePoint::get($order['store_id']);
|
|
|
+ if (!$store) return true;
|
|
|
+
|
|
|
+ $store_leader = SystemAdmin::where('role', sys_config('default_store_admin', 7))
|
|
|
+ ->where('store_id', $store['id'])->where('is_del', 0)->where('status', 1)
|
|
|
+ ->find();
|
|
|
+ if (!$store_leader) return true;
|
|
|
+ $user = User::where('admin_id', $store_leader['id'])->find();
|
|
|
+ if (!$user) return true;
|
|
|
+ $p_user_info = WechatUser::get($user['uid']);
|
|
|
+
|
|
|
+ // 选择发起人的订单作为分账的账单
|
|
|
+ $transaction_id = $order['transaction_id']; // 微信订单号
|
|
|
+ $out_order_no = $order['order_id'];
|
|
|
+
|
|
|
+ // 计算发起人和参与者的分账金额
|
|
|
+ $price = $order['pay_price'] - $order['pay_postage_sh'] - $order['pay_postage'];
|
|
|
+ $p_amount = bcmul($price, sys_config('store_admin_sharing', 0) / 100, 2); //bcmul:2个任意精度数字乘法计算
|
|
|
+ $p_separate_account_amount = floor($p_amount * 100); // 发起人分账金额,以分为单位
|
|
|
+
|
|
|
+ $receivers[] = array(
|
|
|
+ 'type' => 'PERSONAL_OPENID',
|
|
|
+ 'account' => $p_user_info['routine_openid'],
|
|
|
+ 'amount' => $p_separate_account_amount,
|
|
|
+ 'description' => '门店订单'
|
|
|
+ );
|
|
|
+
|
|
|
+ // 记录发起人分账开始的信息
|
|
|
+ $p_separate_account_record = new StoreSeparateAccountRecord();
|
|
|
+ $p_separate_account_record['money'] = $p_amount;
|
|
|
+ $p_separate_account_record['order_id'] = $order_id; // OK
|
|
|
+ $p_separate_account_record['uid'] = $user['uid'];
|
|
|
+ $p_separate_account_record['state'] = 0; // 默认为失败
|
|
|
+ $p_separate_account_record['notice'] = "分账失败";
|
|
|
+ $p_separate_account_record['store_id'] = $order['store_id'];
|
|
|
+ $p_separate_account_record['start_time'] = time();
|
|
|
+ $p_separate_account_record['end_time'] = 0;
|
|
|
+ $p_separate_account_record->save();
|
|
|
+
|
|
|
+ // 添加发起人为分账接受方
|
|
|
+ MiniProgramService::addReceiver($p_user_info['routine_openid']); // 添加发起人为分账接受方
|
|
|
+
|
|
|
+ if ($transaction_id) {
|
|
|
+ $res = MiniProgramService::multi_profit_sharing($transaction_id, $out_order_no, $receivers);
|
|
|
+ $res = json_decode($res, true);
|
|
|
+
|
|
|
+ $separateAccount = StoreSeparateAccountRecord::where('order_id', $order_id)->select();
|
|
|
+ if ($res['return_code'] == 'SUCCESS') {
|
|
|
+ foreach ($separateAccount as $key => $value) {
|
|
|
+ $value['state'] = 1;
|
|
|
+ $value['notice'] = "分账成功";
|
|
|
+ $value['end_time'] = time();
|
|
|
+ $value->save();
|
|
|
+ }
|
|
|
+ MiniProgramService::profit_sharing_finish($order['transaction_id'], $order['order_id']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|