| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- /**
- * @package merchant
- * @Author: Qinii
- * @Date: 2020/5/8
- */
- namespace app\common\repositories\movie;
- use app\common\dao\movie\order\MovieOrderDao;
- use app\common\repositories\BaseRepository;
- use app\common\repositories\store\order\StoreOrderRepository;
- use app\traits\HuiPay;
- use crmeb\services\ApiResponseService;
- use think\exception\ValidateException;
- use think\facade\Db;
- use think\facade\Log;
- /**
- * Class MovieRepository
- * @package app\common\repositories\movie
- * @author xaboy
- * @mixin MovieOrderDao
- */
- class MovieRepository extends BaseRepository
- {
- use HuiPay;
- protected $dao;
- /**
- * ProductRepository constructor.
- * @param MovieOrderDao $dao
- */
- public function __construct(MovieOrderDao $dao)
- {
- $this->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 = '')
- {
- return DouHuoMallFilmApiRequest::getCinemaSched($film_sign, $cinema_sign);
- }
- /**
- * @param $relation_id
- * @param $sched_sign
- * @return mixed|string
- */
- public function getSchedSeat($relation_id = '', $sched_sign = '')
- {
- return DouHuoMallFilmApiRequest::getSchedSeat($relation_id, $sched_sign);
- }
- /**
- * 锁座订单
- * @param $sched_sign
- * @param $seat_sign
- * @param $channel_type
- * @param $third_order
- * @param $order_price
- * @param $phone
- * @return mixed|string
- */
- public function submitOrder($userinfo, $params)
- {
- /** @var StoreOrderRepository $storeOrder */
- $storeOrder = app()->make(StoreOrderRepository::class);
- $order_sn = $storeOrder->getNewOrderId() . '0';
- $order_price = round($params['number'] * $params['price'], 2);
- $submitOrder = DouHuoMallFilmApiRequest::submitOrder($userinfo->phone, $params['channel_type'], $params['sched_sign'], $order_sn, $order_price);
- if (!empty($submitOrder) && isset($submitOrder['code']) && ($submitOrder['code'] == 200) && isset($submitOrder['data']['plat_order'])) {
- $_order = [
- 'uid' => $userinfo->uid,
- 'mobile' => $userinfo->phone,
- 'order_sn' => $order_sn,
- 'plat_order' => $submitOrder['data']['plat_order'],
- 'price' => $params['price'],
- 'number' => $params['number'],
- 'order_price' => $order_price,
- 'channel_type' => $params['channel_type'],
- 'pay_type' => $params['pay_type'],
- 'city_sign' => $params['city_sign'],
- 'city_name' => $params['city_name'],
- 'area_code' => $params['area_code'],
- 'area_name' => $params['area_name'],
- 'cinema_sign' => $params['cinema_sign'],
- 'cinema_name' => $params['cinema_name'],
- 'address' => $params['address'],
- 'longitude' => $params['longitude'],
- 'latitude' => $params['latitude'],
- 'hall_sign' => $params['hall_sign'],
- 'hall_name' => $params['hall_name'],
- 'relation_id' => $params['relation_id'],
- 'sched_sign' => $params['sched_sign'],
- 'film_sign' => $params['film_sign'],
- 'film_name' => $params['film_name'],
- 'show_date' => $params['show_date'],
- 'show_time' => $params['show_time'],
- 'sched_seat' => $params['sched_seat'],
- 'create_time' => time()
- ];
- $group = Db::transaction(function () use ($userinfo, $_order) {
- $_order = $this->dao->create($_order);
- if ($_order) return ['code' => ApiResponseService::DEFAULT_SUCCESS_CODE, 'msg' => '下单成功', 'data' => ['order_sn' => $_order['order_sn']]];
- // return $this->pay(
- // $_order['pay_type'], $userinfo->wechat_user_id, $_order, $_order['film_name'], env('APP_URL') . "/api/hf_notify/movie",
- // 'delay');
- throw new ValidateException('下单失败');
- });
- return $group;
- } else {
- return $submitOrder;
- }
- }
- /**
- * 支付
- *
- * @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 $third_order
- * @param $order_price
- * @return mixed|string
- */
- public function confirmOrder($third_order, $order_price)
- {
- return DouHuoMallFilmApiRequest::confirmOrder($third_order, $order_price);
- }
- /**
- * @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('订单不存在');
- }
- }
|