where(['id' => self::$aid, 'is_del' => CommonModel::$del_normal]) ->findOrEmpty() ->toArray(); if (empty($rs)) return json_show(CommonModel::$error_param, '该账户不存在'); $db = VideoModel::where(['is_del' => CommonModel::$del_normal, 'status' => CommonModel::$status_normal]) ->whereIn('id', $rs['video_ids']); $count = $db->count('id'); $list = $db ->field('id,video_sn,video_name,video_url,video_img') ->page($data['page'], $data['size']) ->order(['weight' => 'desc', 'id' => 'desc']) ->select() ->toArray(); return json_show(CommonModel::$success, '获取视频列表成功', ['count' => $count, 'list' => $list]); } //手机主题 public static function theme(): Json { $rs = ThemeModel::field('id,code') ->where(['is_del' => CommonModel::$del_normal, 'group_id' => self::$group_id, 'status' => CommonModel::$status_normal]) ->append(['modular']) ->withAttr('modular', function ($val, $data) { return Db::name('theme_modular') ->field('id,title,type') ->where(['is_del' => CommonModel::$del_normal, 'theme_id' => $data['id'], 'status' => CommonModel::$status_normal]) ->order(['addtime' => 'desc', 'id' => 'desc']) ->append(['data']) ->withAttr('data', function ($v, $d) { return Db::name('theme_modular_data') ->field('id,img,jump_type,jump_param,good_name,good_id,style_type') ->where(['is_del' => CommonModel::$del_normal, 'theme_modular_id' => $d['id']]) ->order(['addtime' => 'desc', 'id' => 'desc']) ->select() ->toArray(); }) ->select() ->toArray(); }) ->findOrEmpty() ->toArray(); return empty($rs) ? json_show(CommonModel::$error_param, '该手机主题不存在') : json_show(CommonModel::$success, '获取手机主题成功', $rs); } //微信支付预下单 public static function getPrepayId(array $data = []): json { $openId = AccountModel::where(['id' => self::$aid, 'is_del' => CommonModel::$del_normal]) ->value('wx_openId', ''); if ($openId == '') return json_show(CommonModel::$error_token, '获取账户openId失败,请重新登录'); Db::startTrans(); try { $amount = '0';//支付金额 $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]) ->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'], $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); } catch (Exception $exception) { Db::rollback(); return json_show(CommonModel::$success, '微信支付预下单失败' . $exception->getMessage()); } } }