dao = $dao; } /** * @param $page * @param $limit * @param $initial * @param $city_name * @return false|int|mixed */ public function getMovieCity($page = 1, $limit = 10, $initial = '', $city_name = '') { return DouHuoMallFilmApiRequest::getMovieCity($page, $limit, $initial = '', $city_name); } /** * @param $city_sign * @return false|int|mixed */ public function getMovieArea($city_sign = '') { return DouHuoMallFilmApiRequest::getMovieArea($city_sign); } /** * @param $page * @param $limit * @param $city_sign * @param $area_sign * @return false|int|mixed */ public function getCinema($page = 1, $limit = 10, $city_sign = '', $area_sign = '') { return DouHuoMallFilmApiRequest::getCinema($page, $limit, $city_sign, $area_sign); } /** * @param $page * @param $limit * @param $cinema_sign * @param $film_sign * @return false|int|mixed */ public function getFilm($page = 1, $limit = 10, $cinema_sign = '', $film_sign = '') { return DouHuoMallFilmApiRequest::getFilm($page, $limit, $cinema_sign, $film_sign); } /** * @param $film_sign * @param $cinema_sign * @return mixed|string */ public function getCinemaSched($film_sign = '', $cinema_sign = '') { $result = DouHuoMallFilmApiRequest::getCinemaSched($film_sign, $cinema_sign); $cinemaSchedList = (isset($result['code']) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) ? $result['data']['list'] : []; foreach ($cinemaSchedList as $dateDay => &$fileSchedValue) { foreach ($fileSchedValue as $key => $value) { $pcYanglaojinGongxian = static::getPvYanglaojinScore($value['cost_price']); $fileSchedValue[$key]['price'] = $pcYanglaojinGongxian['cost_price']; $fileSchedValue[$key]['yanglaojin'] = $pcYanglaojinGongxian['yanglaojin']; $fileSchedValue[$key]['pv'] = $pcYanglaojinGongxian['pv']; $fileSchedValue[$key]['score'] = $pcYanglaojinGongxian['score']; $fileSchedValue[$key]['gongxian'] = $pcYanglaojinGongxian['gongxian']; // unset($fileSchedValue[$key]['channel_price']); } } return $cinemaSchedList; } /** * @param $relation_id * @param $sched_sign * @return mixed|string */ public function getSchedSeat($relation_id = '', $sched_sign = '') { $result = DouHuoMallFilmApiRequest::getSchedSeat($relation_id, $sched_sign); $schedSeatList = (isset($result['code']) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) ? $result['data']['list'] : []; foreach ($schedSeatList as $key => $value) { $tmpprice = json_decode($value['price'], true); if (isset($tmpprice['P2'])) { $price = $tmpprice['P2']; } elseif (isset($tmpprice['P1'])) { $price = $tmpprice['P1']; } elseif (isset($tmpprice['P0'])) { $price = $tmpprice['P0']; } else { $price = 0.00; } unset($schedSeatList[$key]['price']); $pcYanglaojinGongxian = self::getPvYanglaojinScore($price); $schedSeatList[$key]['price'] = $pcYanglaojinGongxian['cost_price']; $schedSeatList[$key]['yanglaojin'] = $pcYanglaojinGongxian['yanglaojin']; $schedSeatList[$key]['pv'] = $pcYanglaojinGongxian['pv']; $schedSeatList[$key]['score'] = $pcYanglaojinGongxian['score']; $schedSeatList[$key]['gongxian'] = $pcYanglaojinGongxian['gongxian']; $schedSeatList[$key]['relation_id'] = $relation_id; // 场次ID $schedSeatList[$key]['sched_sign'] = $sched_sign; // 场次编码 } return $schedSeatList; } /** * 锁座订单 * * @param $userinfo * @param $params * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function submitOrder($userinfo, $params) { /** @var StoreOrderRepository $storeOrder */ $storeOrder = app()->make(StoreOrderRepository::class); $order_sn = $storeOrder->getNewOrderId() . '0'; /** @var CinemaSchedRepository $cinemaSchedRepository */ $cinemaSchedRepository = app()->make(CinemaSchedRepository::class); $sched = $cinemaSchedRepository->getCinemaSchedInfo($params['relation_id'], $params['sched_sign']); if (empty($sched)) throw new ValidateException('观影场次不存在'); $seat_sign = json_decode($params['seat_sign'], true); $order_price = round($sched['price'] * count($seat_sign), 2); $submitOrder = DouHuoMallFilmApiRequest::submitOrder($userinfo->phone, $params['channel_type'], $params['sched_sign'], $seat_sign, $order_sn, $order_price); if (!empty($submitOrder) && isset($submitOrder['code']) && ($submitOrder['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE) && isset($submitOrder['data']['plat_order'])) { /** @var CinemaRepository $cinemaRepository */ $cinemaRepository = app()->make(CinemaRepository::class); $cinema = $cinemaRepository->getCinemaInfo($sched['cinema_sign']); $_order = [ 'uid' => $userinfo->uid, 'mobile' => $userinfo->phone, 'order_sn' => $order_sn, 'plat_order' => $submitOrder['data']['plat_order'], 'price' => $sched['price'], 'number' => count($seat_sign), 'order_price' => $order_price, 'channel_type' => $params['channel_type'], 'city_sign' => $cinema['city_sign'], 'city_name' => $cinema['city_name'], 'area_code' => $cinema['area_sign'], 'area_name' => $cinema['area_name'], 'cinema_sign' => $cinema['cinema_sign'], 'cinema_name' => $cinema['cinema_name'], 'address' => $cinema['address'], 'longitude' => $cinema['longitude'], 'latitude' => $cinema['latitude'], 'hall_sign' => $sched['hall_sign'], 'hall_name' => $sched['hall_name'], 'relation_id' => $sched['relation_id'], 'sched_sign' => $sched['sched_sign'], 'film_sign' => $sched['film_sign'], 'film_name' => $sched['film_name'], 'show_date' => $sched['show_date'], 'show_time' => $sched['show_time'], 'sched_seat' => $sched['sched_seat'], 'create_time' => time() ]; $order_sn = Db::transaction(function () use ($userinfo, $_order) { $_order = $this->dao->create($_order); if ($_order) return $_order['order_sn']; throw new ValidateException('锁座下单失败'); }); return $order_sn; } else { throw new ValidateException('锁座下单失败'); } } /** * @param $userinfo * @param $order_sn * @return mixed|string */ public function confirmOrder($userinfo, $order_sn) { $orderinfo = $this->dao->getWhere(['order_sn' => $order_sn, 'uid' => $userinfo->uid])->find(); if (empty($orderinfo)) throw new ValidateException('订单不存在'); if ($orderinfo['paid'] == 0 && $orderinfo['status'] == 2) throw new ValidateException('订单已超时'); if ($orderinfo['paid'] == 0 && $orderinfo['status'] == 3) throw new ValidateException('订单已取消'); if ($orderinfo['paid'] == 1) throw new ValidateException('订单已支付'); // return $this->pay( // $_order['pay_type'], $userinfo->wechat_user_id, $_order, $_order['film_name'], env('APP_URL') . "/api/hf_notify/movie", // 'delay'); return DouHuoMallFilmApiRequest::confirmOrder($orderinfo['order_sn'], $orderinfo['order_price']); } /** * 支付 * * @param $payType * @param $openid * @param $_order * @param $title * @param $notify_url * @param $pay_mode * @param $appid * @return array|mixed */ private function pay($payType, $openid, $_order, $title, $notify_url, $pay_mode = null, $appid = '') { switch ($payType) { case 'wx': $pay_wx = systemConfig('pay_wx'); if ($pay_wx == 2) { $appid = env('WECHAT_MP.APPID'); $new_secret = env('WECHAT_MP.SECRET'); $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419'; $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f'; } elseif ($pay_wx == 3) { $appid = env('WECHAT_TDYL.APPID'); $new_secret = env('WECHAT_TDYL.SECRET'); $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0'; $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871'; } $type = '2'; $params = [ 'order_no' => $_order['order_sn'], 'app_id' => $app_id, 'pay_channel' => 'wx_lite', 'pay_amt' => (string)$_order['order_price'], 'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题 'device_info' => [ 'device_ip' => app('request')->ip() ], 'expend' => json_encode(['open_id' => $openid, 'wx_app_id' => $appid]), 'fee_mode' => 'I', 'notify_url' => $notify_url, 'pay_mode' => $pay_mode ]; break; case 'ALI': $type = '1'; // 天地博爱科技通道 $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f'; $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9'; $params = [ 'order_no' => $_order['order_sn'], 'app_id' => $app_id, 'pay_channel' => 'alipay_qr', 'pay_amt' => (string)$_order['order_price'], 'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题 'device_info' => [ 'device_ip' => app('request')->ip() ], 'fee_mode' => 'I', 'notify_url' => $notify_url ]; break; default: throw new ValidateException('请选择支付方式'); break; } return $this->Payment_create_traits_a($params, $type, $key); } /** * @param $userinfo * @param $order_sn * @return mixed|string */ public function getOrderInfo($userinfo, $order_sn) { $orderinfo = $this->dao->getWhere(['order_sn' => $order_sn, 'uid' => $userinfo->uid])->find(); if (empty($orderinfo)) throw new ValidateException('订单不存在'); $result = DouHuoMallFilmApiRequest::getOrderInfo($order_sn); if (!empty($result) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) return $result['data']; throw new ValidateException('订单不存在'); } /** * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getLocalMovieCity() { $city_name = []; $city = Db::name('movie_city')->field('city_sign,city_name,initial')->where('is_show', 1)->order('id asc')->select(); foreach ($city as $key => $value) { $city_name[$value['initial']][] = ['city_sign' => $value['city_sign'], 'city_name' => $value['city_name']]; } $initial = !empty($city) ? array_values(array_column($city->toArray(), 'initial', 'initial')) : []; return compact('city_name', 'initial'); } /** * 获取pv、养老金、售价、积分 * * @param $cost_price * @return array */ public static function getPvYanglaojinScore($cost_price) { $premium = round($cost_price * self::premium_ratio, 2); $cost_price = bcadd((string)$cost_price, (string)$premium, 2); $pv = $gongxian = $score = bcmul((string)$premium, self::pv_ratio, 2); $yanglaojin = bcmul((string)$premium, self::yanglaojin_ratio, 2); return compact('premium', 'cost_price', 'pv', 'yanglaojin', 'gongxian', 'score'); } }