|
@@ -4,7 +4,9 @@ namespace app\mobile\logic;
|
|
|
|
|
|
use app\model\AccountModel;
|
|
|
use app\model\CommonModel;
|
|
|
+use app\model\GoodModel;
|
|
|
use app\model\GroupModel;
|
|
|
+use app\model\PayInfoModel;
|
|
|
use app\model\ServiceModel;
|
|
|
use app\model\ThemeModel;
|
|
|
use app\model\VideoModel;
|
|
@@ -71,7 +73,6 @@ class CommonLogic extends BaseLogic
|
|
|
//微信支付预下单
|
|
|
public static function getPrepayId(array $data = []): json
|
|
|
{
|
|
|
-
|
|
|
$openId = AccountModel::where(['id' => self::$aid, 'is_del' => CommonModel::$del_normal])
|
|
|
->value('wx_openId', '');
|
|
|
|
|
@@ -81,33 +82,60 @@ class CommonLogic extends BaseLogic
|
|
|
|
|
|
try {
|
|
|
|
|
|
-
|
|
|
$amount = '0';//支付金额
|
|
|
- if($data['type'] == CommonModel::$pay_type_service){
|
|
|
+ $num = array_column($data['list'], 'num', 'id');//
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ if ($data['type'] == CommonModel::$pay_type_service) {
|
|
|
//购买服务
|
|
|
- $rs=ServiceModel::field('id,original_price,activity_price,title,activity_status')
|
|
|
- ->whereIn('id',array_column($data['list'],'id'))
|
|
|
- ->where(['is_del'=>CommonModel::$del_normal,'status'=>CommonModel::$status_normal])
|
|
|
+ $rs = ServiceModel::field('id,original_price,activity_price,title,activity_status')
|
|
|
+ ->whereIn('id', array_column($data['list'], 'id'))
|
|
|
+ ->where(['is_del' => CommonModel::$del_normal, 'status' => CommonModel::$status_normal])
|
|
|
->select()
|
|
|
->toArray();
|
|
|
- if(empty($rs)) throw new Exception('购买的服务不存在或已下架');
|
|
|
-
|
|
|
- foreach ($rs as $item){
|
|
|
-
|
|
|
- if($item['activity_status'] == ServiceModel::$activity_status_ing) $amount = bcadd($amount,bcmul($rs['activity_price'],$),2);
|
|
|
-
|
|
|
+ if (empty($rs)) throw new Exception('购买的服务不存在或已下架');
|
|
|
|
|
|
+ foreach ($rs as $item) {
|
|
|
+ if ($item['activity_status'] == ServiceModel::$activity_status_ing) $amount = bcadd($amount, bcmul($rs['activity_price'], $num[$item['id']] ?? 0), 2);
|
|
|
+ else $amount = bcadd($amount, bcmul($rs['original_price'], $num[$item['id']] ?? 0), 2);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ //购买商城商品
|
|
|
+ $rs = GoodModel::field('id,price,good_name')
|
|
|
+ ->whereIn('id', array_column($data['list'], 'id'))
|
|
|
+ ->where(['is_del' => CommonModel::$del_normal, 'status' => CommonModel::$status_normal])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ if (empty($rs)) throw new Exception('购买的商品不存在或已禁用');
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ foreach ($rs as $item) {
|
|
|
+ $amount = bcadd($amount, bcmul($rs['price'], $num[$item['id']] ?? 0), 2);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ $code = make_no('ZF');
|
|
|
+
|
|
|
+ //获取预支付信息
|
|
|
+ $result = WechatLogic::getPrepayId($openId, '', $code, $amount);
|
|
|
+
|
|
|
+ PayInfoModel::create([
|
|
|
+ 'code' => $code,
|
|
|
+ 'wx_openId' => $openId,
|
|
|
+ 'type' => $data['type'],
|
|
|
+ 'ids' => json_encode($data['list']),
|
|
|
+ 'prepay_info' => $result,
|
|
|
+ 'amount' => $amount,
|
|
|
+ '' => '',//流水号
|
|
|
+ 'expiretime' => date('Y-m-d H:i:s', time() + 5 * 60),
|
|
|
+ 'status' => PayInfoModel::$pay_wait,
|
|
|
+ 'createrid' => self::$aid,
|
|
|
+ 'creater' => self::$aname,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updaterid' => self::$aid,
|
|
|
+ 'updater' => self::$aname,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ])->save();
|
|
|
|
|
|
Db::commit();
|
|
|
return json_show(CommonModel::$success, '微信支付预下单成功', $res);
|