MovieRepository.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/8
  6. */
  7. namespace app\common\repositories\movie;
  8. use app\common\dao\movie\order\MovieOrderDao;
  9. use app\common\repositories\BaseRepository;
  10. use app\common\repositories\store\order\StoreOrderRepository;
  11. use app\traits\HuiPay;
  12. use crmeb\services\ApiResponseService;
  13. use think\exception\ValidateException;
  14. use think\facade\Db;
  15. use think\facade\Log;
  16. /**
  17. * Class MovieRepository
  18. * @package app\common\repositories\movie
  19. * @author xaboy
  20. * @mixin MovieOrderDao
  21. */
  22. class MovieRepository extends BaseRepository
  23. {
  24. use HuiPay;
  25. protected $dao;
  26. /**
  27. * ProductRepository constructor.
  28. * @param MovieOrderDao $dao
  29. */
  30. public function __construct(MovieOrderDao $dao)
  31. {
  32. $this->dao = $dao;
  33. }
  34. /**
  35. * @param $page
  36. * @param $limit
  37. * @param $initial
  38. * @param $city_name
  39. * @return false|int|mixed
  40. */
  41. public function getMovieCity($page = 1, $limit = 10, $initial = '', $city_name = '')
  42. {
  43. return DouHuoMallFilmApiRequest::getMovieCity($page, $limit, $initial = '', $city_name);
  44. }
  45. /**
  46. * @param $city_sign
  47. * @return false|int|mixed
  48. */
  49. public function getMovieArea($city_sign = '')
  50. {
  51. return DouHuoMallFilmApiRequest::getMovieArea($city_sign);
  52. }
  53. /**
  54. * @param $page
  55. * @param $limit
  56. * @param $city_sign
  57. * @param $area_sign
  58. * @return false|int|mixed
  59. */
  60. public function getCinema($page = 1, $limit = 10, $city_sign = '', $area_sign = '')
  61. {
  62. return DouHuoMallFilmApiRequest::getCinema($page, $limit, $city_sign, $area_sign);
  63. }
  64. /**
  65. * @param $page
  66. * @param $limit
  67. * @param $cinema_sign
  68. * @param $film_sign
  69. * @return false|int|mixed
  70. */
  71. public function getFilm($page = 1, $limit = 10, $cinema_sign = '', $film_sign = '')
  72. {
  73. return DouHuoMallFilmApiRequest::getFilm($page, $limit, $cinema_sign, $film_sign);
  74. }
  75. /**
  76. * @param $film_sign
  77. * @param $cinema_sign
  78. * @return mixed|string
  79. */
  80. public function getCinemaSched($film_sign = '', $cinema_sign = '')
  81. {
  82. return DouHuoMallFilmApiRequest::getCinemaSched($film_sign, $cinema_sign);
  83. }
  84. /**
  85. * @param $relation_id
  86. * @param $sched_sign
  87. * @return mixed|string
  88. */
  89. public function getSchedSeat($relation_id = '', $sched_sign = '')
  90. {
  91. return DouHuoMallFilmApiRequest::getSchedSeat($relation_id, $sched_sign);
  92. }
  93. /**
  94. * 锁座订单
  95. * @param $sched_sign
  96. * @param $seat_sign
  97. * @param $channel_type
  98. * @param $third_order
  99. * @param $order_price
  100. * @param $phone
  101. * @return mixed|string
  102. */
  103. public function submitOrder($userinfo, $params)
  104. {
  105. /** @var StoreOrderRepository $storeOrder */
  106. $storeOrder = app()->make(StoreOrderRepository::class);
  107. $order_sn = $storeOrder->getNewOrderId() . '0';
  108. $order_price = round($params['number'] * $params['price'], 2);
  109. $submitOrder = DouHuoMallFilmApiRequest::submitOrder($userinfo->phone, $params['channel_type'], $params['sched_sign'], $order_sn, $order_price);
  110. if (!empty($submitOrder) && isset($submitOrder['code']) && ($submitOrder['code'] == 200) && isset($submitOrder['data']['plat_order'])) {
  111. $_order = [
  112. 'uid' => $userinfo->uid,
  113. 'mobile' => $userinfo->phone,
  114. 'order_sn' => $order_sn,
  115. 'plat_order' => $submitOrder['data']['plat_order'],
  116. 'price' => $params['price'],
  117. 'number' => $params['number'],
  118. 'order_price' => $order_price,
  119. 'channel_type' => $params['channel_type'],
  120. 'pay_type' => $params['pay_type'],
  121. 'city_sign' => $params['city_sign'],
  122. 'city_name' => $params['city_name'],
  123. 'area_code' => $params['area_code'],
  124. 'area_name' => $params['area_name'],
  125. 'cinema_sign' => $params['cinema_sign'],
  126. 'cinema_name' => $params['cinema_name'],
  127. 'address' => $params['address'],
  128. 'longitude' => $params['longitude'],
  129. 'latitude' => $params['latitude'],
  130. 'hall_sign' => $params['hall_sign'],
  131. 'hall_name' => $params['hall_name'],
  132. 'relation_id' => $params['relation_id'],
  133. 'sched_sign' => $params['sched_sign'],
  134. 'film_sign' => $params['film_sign'],
  135. 'film_name' => $params['film_name'],
  136. 'show_date' => $params['show_date'],
  137. 'show_time' => $params['show_time'],
  138. 'sched_seat' => $params['sched_seat'],
  139. 'create_time' => time()
  140. ];
  141. $group = Db::transaction(function () use ($userinfo, $_order) {
  142. $_order = $this->dao->create($_order);
  143. if ($_order) return ['code' => ApiResponseService::DEFAULT_SUCCESS_CODE, 'msg' => '下单成功', 'data' => ['order_sn' => $_order['order_sn']]];
  144. throw new ValidateException('下单失败');
  145. });
  146. return $group;
  147. } else {
  148. return $submitOrder;
  149. }
  150. }
  151. /**
  152. * @param $userinfo
  153. * @param $order_sn
  154. * @return mixed|string
  155. */
  156. public function confirmOrder($userinfo, $order_sn)
  157. {
  158. $orderinfo = $this->dao->getWhere(['order_sn' => $order_sn, 'uid' => $userinfo->uid])->find();
  159. if (empty($orderinfo)) throw new ValidateException('订单不存在');
  160. if ($orderinfo['paid'] == 0 && $orderinfo['status'] == 2) throw new ValidateException('订单已超时');
  161. if ($orderinfo['paid'] == 0 && $orderinfo['status'] == 3) throw new ValidateException('订单已取消');
  162. if ($orderinfo['paid'] == 1) throw new ValidateException('订单已支付');
  163. // return $this->pay(
  164. // $_order['pay_type'], $userinfo->wechat_user_id, $_order, $_order['film_name'], env('APP_URL') . "/api/hf_notify/movie",
  165. // 'delay');
  166. return DouHuoMallFilmApiRequest::confirmOrder($third_order, $order_price);
  167. }
  168. /**
  169. * 支付
  170. *
  171. * @param $payType
  172. * @param $openid
  173. * @param $_order
  174. * @param $title
  175. * @param $notify_url
  176. * @param $pay_mode
  177. * @param $appid
  178. * @return array|mixed
  179. */
  180. private function pay($payType, $openid, $_order, $title, $notify_url, $pay_mode = null, $appid = '')
  181. {
  182. switch ($payType) {
  183. case 'wx':
  184. $pay_wx = systemConfig('pay_wx');
  185. if ($pay_wx == 2) {
  186. $appid = env('WECHAT_MP.APPID');
  187. $new_secret = env('WECHAT_MP.SECRET');
  188. $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
  189. $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  190. } elseif ($pay_wx == 3) {
  191. $appid = env('WECHAT_TDYL.APPID');
  192. $new_secret = env('WECHAT_TDYL.SECRET');
  193. $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  194. $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  195. }
  196. $type = '2';
  197. $params = [
  198. 'order_no' => $_order['order_sn'],
  199. 'app_id' => $app_id,
  200. 'pay_channel' => 'wx_lite',
  201. 'pay_amt' => (string)$_order['order_price'],
  202. 'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题
  203. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题
  204. 'device_info' => [
  205. 'device_ip' => app('request')->ip()
  206. ],
  207. 'expend' => json_encode(['open_id' => $openid, 'wx_app_id' => $appid]),
  208. 'fee_mode' => 'I',
  209. 'notify_url' => $notify_url,
  210. 'pay_mode' => $pay_mode
  211. ];
  212. break;
  213. case 'ALI':
  214. $type = '1';
  215. // 天地博爱科技通道
  216. $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
  217. $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  218. $params = [
  219. 'order_no' => $_order['order_sn'],
  220. 'app_id' => $app_id,
  221. 'pay_channel' => 'alipay_qr',
  222. 'pay_amt' => (string)$_order['order_price'],
  223. 'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题
  224. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题
  225. 'device_info' => [
  226. 'device_ip' => app('request')->ip()
  227. ],
  228. 'fee_mode' => 'I',
  229. 'notify_url' => $notify_url
  230. ];
  231. break;
  232. default:
  233. throw new ValidateException('请选择支付方式');
  234. break;
  235. }
  236. return $this->Payment_create_traits_a($params, $type, $key);
  237. }
  238. /**
  239. * @param $userinfo
  240. * @param $order_sn
  241. * @return mixed|string
  242. */
  243. public function getOrderInfo($userinfo, $order_sn)
  244. {
  245. $orderinfo = $this->dao->getWhere(['order_sn' => $order_sn, 'uid' => $userinfo->uid])->find();
  246. if (empty($orderinfo)) throw new ValidateException('订单不存在');
  247. $result = DouHuoMallFilmApiRequest::getOrderInfo($order_sn);
  248. if (!empty($result) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) return $result['data'];
  249. throw new ValidateException('订单不存在');
  250. }
  251. }