MovieRepository.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. // return $this->pay(
  145. // $_order['pay_type'], $userinfo->wechat_user_id, $_order, $_order['film_name'], env('APP_URL') . "/api/hf_notify/movie",
  146. // 'delay');
  147. throw new ValidateException('下单失败');
  148. });
  149. return $group;
  150. } else {
  151. return $submitOrder;
  152. }
  153. }
  154. /**
  155. * 支付
  156. *
  157. * @param $payType
  158. * @param $openid
  159. * @param $_order
  160. * @param $title
  161. * @param $notify_url
  162. * @param $pay_mode
  163. * @param $appid
  164. * @return array|mixed
  165. */
  166. private function pay($payType, $openid, $_order, $title, $notify_url, $pay_mode = null, $appid = '')
  167. {
  168. switch ($payType) {
  169. case 'wx':
  170. $pay_wx = systemConfig('pay_wx');
  171. if ($pay_wx == 2) {
  172. $appid = env('WECHAT_MP.APPID');
  173. $new_secret = env('WECHAT_MP.SECRET');
  174. $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
  175. $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  176. } elseif ($pay_wx == 3) {
  177. $appid = env('WECHAT_TDYL.APPID');
  178. $new_secret = env('WECHAT_TDYL.SECRET');
  179. $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  180. $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  181. }
  182. $type = '2';
  183. $params = [
  184. 'order_no' => $_order['order_sn'],
  185. 'app_id' => $app_id,
  186. 'pay_channel' => 'wx_lite',
  187. 'pay_amt' => (string)$_order['order_price'],
  188. 'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题
  189. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题
  190. 'device_info' => [
  191. 'device_ip' => app('request')->ip()
  192. ],
  193. 'expend' => json_encode(['open_id' => $openid, 'wx_app_id' => $appid]),
  194. 'fee_mode' => 'I',
  195. 'notify_url' => $notify_url,
  196. 'pay_mode' => $pay_mode
  197. ];
  198. break;
  199. case 'ALI':
  200. $type = '1';
  201. // 天地博爱科技通道
  202. $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
  203. $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  204. $params = [
  205. 'order_no' => $_order['order_sn'],
  206. 'app_id' => $app_id,
  207. 'pay_channel' => 'alipay_qr',
  208. 'pay_amt' => (string)$_order['order_price'],
  209. 'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题
  210. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题
  211. 'device_info' => [
  212. 'device_ip' => app('request')->ip()
  213. ],
  214. 'fee_mode' => 'I',
  215. 'notify_url' => $notify_url
  216. ];
  217. break;
  218. default:
  219. throw new ValidateException('请选择支付方式');
  220. break;
  221. }
  222. return $this->Payment_create_traits_a($params, $type, $key);
  223. }
  224. /**
  225. * @param $third_order
  226. * @param $order_price
  227. * @return mixed|string
  228. */
  229. public function confirmOrder($third_order, $order_price)
  230. {
  231. return DouHuoMallFilmApiRequest::confirmOrder($third_order, $order_price);
  232. }
  233. /**
  234. * @param $userinfo
  235. * @param $order_sn
  236. * @return mixed|string
  237. */
  238. public function getOrderInfo($userinfo, $order_sn)
  239. {
  240. $orderinfo = $this->dao->getWhere(['order_sn' => $order_sn, 'uid' => $userinfo->uid])->find();
  241. if (empty($orderinfo)) throw new ValidateException('订单不存在');
  242. $result = DouHuoMallFilmApiRequest::getOrderInfo($order_sn);
  243. if (!empty($result) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) return $result['data'];
  244. throw new ValidateException('订单不存在');
  245. }
  246. }