MovieRepository.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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\model\movie\order\MovieOrder;
  10. use app\common\repositories\BaseRepository;
  11. use app\common\repositories\merchant\order\OrderMerchantRepository;
  12. use app\common\repositories\store\order\StoreOrderRepository;
  13. use app\traits\HuiPay;
  14. use crmeb\services\ApiResponseService;
  15. use think\exception\ValidateException;
  16. use think\facade\Db;
  17. /**
  18. * Class MovieRepository
  19. * @package app\common\repositories\movie
  20. * @author xaboy
  21. * @mixin MovieOrderDao
  22. */
  23. class MovieRepository extends BaseRepository
  24. {
  25. use HuiPay;
  26. protected $dao;
  27. const premium_ratio = 0.2;//溢价比例
  28. const yanglaojin_ratio = 0.3;
  29. const pv_ratio = 0.7;
  30. /**
  31. * ProductRepository constructor.
  32. * @param MovieOrderDao $dao
  33. */
  34. public function __construct(MovieOrderDao $dao)
  35. {
  36. $this->dao = $dao;
  37. }
  38. /**
  39. * @param $page
  40. * @param $limit
  41. * @param $initial
  42. * @param $city_name
  43. * @return false|int|mixed
  44. */
  45. public function getMovieCity($page = 1, $limit = 10, $initial = '', $city_name = '')
  46. {
  47. return DouHuoMallFilmApiRequest::getMovieCity($page, $limit, $initial = '', $city_name);
  48. }
  49. /**
  50. * @param $city_sign
  51. * @return false|int|mixed
  52. */
  53. public function getMovieArea($city_sign = '')
  54. {
  55. return DouHuoMallFilmApiRequest::getMovieArea($city_sign);
  56. }
  57. /**
  58. * @param $page
  59. * @param $limit
  60. * @param $city_sign
  61. * @param $area_sign
  62. * @return false|int|mixed
  63. */
  64. public function getCinema($page = 1, $limit = 10, $city_sign = '', $area_sign = '')
  65. {
  66. return DouHuoMallFilmApiRequest::getCinema($page, $limit, $city_sign, $area_sign);
  67. }
  68. /**
  69. * @param $page
  70. * @param $limit
  71. * @param $cinema_sign
  72. * @param $film_sign
  73. * @return false|int|mixed
  74. */
  75. public function getFilm($page = 1, $limit = 10, $cinema_sign = '', $film_sign = '')
  76. {
  77. return DouHuoMallFilmApiRequest::getFilm($page, $limit, $cinema_sign, $film_sign);
  78. }
  79. /**
  80. * @param $film_sign
  81. * @param $cinema_sign
  82. * @return mixed|string
  83. */
  84. public function getCinemaSched($film_sign = '', $cinema_sign = '')
  85. {
  86. $result = DouHuoMallFilmApiRequest::getCinemaSched($film_sign, $cinema_sign);
  87. $cinemaSchedList = (isset($result['code']) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE))
  88. ? $result['data']['list'] : [];
  89. foreach ($cinemaSchedList as $dateDay => &$fileSchedValue) {
  90. foreach ($fileSchedValue as $key => $value) {
  91. $pcYanglaojinGongxian = static::getPvYanglaojinScore($value['cost_price']);
  92. $fileSchedValue[$key]['price'] = $pcYanglaojinGongxian['cost_price']; // 销售价
  93. $fileSchedValue[$key]['yanglaojin'] = $pcYanglaojinGongxian['yanglaojin'];
  94. $fileSchedValue[$key]['pv'] = $pcYanglaojinGongxian['pv'];
  95. $fileSchedValue[$key]['score'] = $pcYanglaojinGongxian['score'];
  96. $fileSchedValue[$key]['gongxian'] = $pcYanglaojinGongxian['gongxian'];
  97. // unset($fileSchedValue[$key]['channel_price']);
  98. }
  99. }
  100. return $cinemaSchedList;
  101. }
  102. /**
  103. * @param $relation_id
  104. * @param $sched_sign
  105. * @return mixed|string
  106. */
  107. public function getSchedSeat($relation_id = '', $sched_sign = '')
  108. {
  109. $result = DouHuoMallFilmApiRequest::getSchedSeat($relation_id, $sched_sign);
  110. $seat = [];
  111. $schedSeatList = (isset($result['code']) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) ? $result['data'] : [];
  112. foreach ($schedSeatList as $key => $value) {
  113. $tmpprice = [];
  114. foreach ($value['price'] as $pKey => $pValue) {
  115. $tmpprice[$pKey] = ['channel_type' => $pKey, 'price' => $pValue];
  116. }
  117. $channel_price = [];
  118. if (isset($tmpprice['P2'])) {
  119. $channel_price = $tmpprice['P2'];
  120. } elseif (isset($tmpprice['P1'])) {
  121. $channel_price = $tmpprice['P1'];
  122. } elseif (isset($tmpprice['P0'])) {
  123. $channel_price = $tmpprice['P0'];
  124. }
  125. unset($schedSeatList[$key]['price']);
  126. $pcYanglaojinGongxian = self::getPvYanglaojinScore($channel_price['price']);
  127. $schedSeatList[$key]['channel_sn'] = base64_encode(json_encode($channel_price, JSON_FORCE_OBJECT));
  128. $schedSeatList[$key]['price'] = $pcYanglaojinGongxian['cost_price'];
  129. $schedSeatList[$key]['yanglaojin'] = $pcYanglaojinGongxian['yanglaojin'];
  130. $schedSeatList[$key]['pv'] = $pcYanglaojinGongxian['pv'];
  131. $schedSeatList[$key]['score'] = $pcYanglaojinGongxian['score'];
  132. $schedSeatList[$key]['gongxian'] = $pcYanglaojinGongxian['gongxian'];
  133. $schedSeatList[$key]['relation_id'] = $relation_id; // 场次ID
  134. $schedSeatList[$key]['sched_sign'] = $sched_sign; // 场次编码
  135. $seat[$value['rowNo']][] = $schedSeatList[$key];
  136. }
  137. if ($seat) ksort($seat);
  138. return array_values($seat);
  139. }
  140. /**
  141. * 锁座订单
  142. *
  143. * @param $userinfo
  144. * @param $params
  145. * @return mixed
  146. * @throws \think\db\exception\DataNotFoundException
  147. * @throws \think\db\exception\DbException
  148. * @throws \think\db\exception\ModelNotFoundException
  149. */
  150. public function submitOrder($userinfo, $params)
  151. {
  152. /** @var StoreOrderRepository $storeOrder */
  153. $storeOrder = app()->make(StoreOrderRepository::class);
  154. $order_sn = substr($storeOrder->getNewOrderId(), 0, 20);
  155. /** @var CinemaSchedRepository $cinemaSchedRepository */
  156. $cinemaSchedRepository = app()->make(CinemaSchedRepository::class);
  157. $sched = $cinemaSchedRepository->getCinemaSchedInfo($params['relation_id'], $params['sched_sign']);
  158. if (empty($sched)) throw new ValidateException('观影场次不存在');
  159. $channel_sn = json_decode(base64_decode($params['channel_sn']), true);
  160. if (empty($channel_sn) || !isset($channel_sn['channel_type']) || empty($channel_sn['channel_type']) || !isset($channel_sn['price'])
  161. || empty($channel_sn['price']) || json_last_error()) {
  162. throw new ValidateException('请选择观影场次');
  163. }
  164. $sched_seat = json_decode($params['sched_seat'], true);
  165. if (json_last_error()) throw new ValidateException('锁座下单失败');
  166. $order_price = bcmul((string)$channel_sn['price'], (string)count($sched_seat), 2);
  167. $submitOrder = DouHuoMallFilmApiRequest::submitOrder($userinfo->phone, $channel_sn['channel_type'], $params['sched_sign'], array_column($sched_seat, 'seat_sign'), $order_sn, $order_price);
  168. if (!empty($submitOrder) && isset($submitOrder['code']) && ($submitOrder['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE) && isset($submitOrder['data']['plat_order'])) {
  169. /** @var CinemaRepository $cinemaRepository */
  170. $cinemaRepository = app()->make(CinemaRepository::class);
  171. $cinema = $cinemaRepository->getCinemaInfo($sched['cinema_sign']);
  172. $_order = [
  173. 'uid' => $userinfo->uid,
  174. 'mobile' => $userinfo->phone,
  175. 'order_sn' => $order_sn,
  176. 'plat_order' => $submitOrder['data']['plat_order'],
  177. 'price' => $order_price,
  178. 'number' => count($sched_seat),
  179. 'order_price' => bcadd((string)$order_price, bcmul((string)$order_price, (string)self::premium_ratio, 2), 2),
  180. 'channel_type' => $channel_sn['channel_type'],
  181. 'city_sign' => $cinema['city_sign'],
  182. 'city_name' => $cinema['city_name'],
  183. 'area_code' => $cinema['area_sign'],
  184. 'area_name' => $cinema['area_name'],
  185. 'cinema_sign' => $cinema['cinema_sign'],
  186. 'cinema_name' => $cinema['cinema_name'],
  187. 'address' => $cinema['address'],
  188. 'longitude' => $cinema['longitude'],
  189. 'latitude' => $cinema['latitude'],
  190. 'hall_sign' => $sched['hall_sign'],
  191. 'hall_name' => $sched['hall_name'],
  192. 'relation_id' => $sched['relation_id'],
  193. 'sched_sign' => $sched['sched_sign'],
  194. 'film_sign' => $sched['film_sign'],
  195. 'film_name' => $sched['film_name'],
  196. 'show_date' => $sched['show_date'],
  197. 'show_time' => $sched['show_time'],
  198. 'sched_seat' => $params['sched_seat'], // 场次座位
  199. 'create_time' => time()
  200. ];
  201. $order_sn = Db::transaction(function () use ($userinfo, $_order) {
  202. $_order = $this->dao->create($_order);
  203. if ($_order) return $_order['order_sn'];
  204. throw new ValidateException('锁座下单失败');
  205. });
  206. return $order_sn;
  207. } else {
  208. throw new ValidateException('锁座下单失败');
  209. }
  210. }
  211. /**
  212. * @param $userinfo
  213. * @param $order_sn
  214. * @param $pay_type
  215. * @return mixed
  216. * @throws \think\db\exception\DataNotFoundException
  217. * @throws \think\db\exception\DbException
  218. * @throws \think\db\exception\ModelNotFoundException
  219. */
  220. public function confirmOrder($userinfo, $order_sn, $pay_type)
  221. {
  222. $orderinfo = $this->dao->search(['order_sn' => $order_sn, 'uid' => $userinfo['uid']])->find();
  223. if (empty($orderinfo)) throw new ValidateException('订单不存在');
  224. if ($orderinfo['paid'] == 0 && $orderinfo['status'] == 2) throw new ValidateException('订单已超时');
  225. if ($orderinfo['paid'] == 0 && $orderinfo['status'] == 3) throw new ValidateException('订单已取消');
  226. if ($orderinfo['paid'] == 1) throw new ValidateException('订单已支付');
  227. $res = $this->pay($pay_type, $userinfo['wechat_user_id'], $orderinfo, $orderinfo['film_name'], env('APP_URL') . "/api/hf_notify/movie", 'delay');
  228. Db::name('log')->insert(['data' => '汇付电影票订单支付--- 返回参数' . json_encode($res)]);
  229. if (isset($res['id'])) {
  230. $type = 0;
  231. if ($pay_type == 'wx') $type = 2;
  232. if (strtolower($pay_type) == 'ali') $type = 1;
  233. $orderinfo->pay_type = $type;
  234. $orderinfo->update_time = time();
  235. $orderinfo->save();
  236. return app('json')->success($res);
  237. }
  238. throw new ValidateException('支付失败');
  239. }
  240. /**
  241. * 支付
  242. *
  243. * @param $payType
  244. * @param $openid
  245. * @param $_order
  246. * @param $title
  247. * @param $notify_url
  248. * @param $pay_mode
  249. * @param $appid
  250. * @return array|mixed
  251. */
  252. private function pay($payType, $openid, $_order, $title, $notify_url, $pay_mode = null, $appid = '')
  253. {
  254. switch ($payType) {
  255. case 'wx':
  256. $pay_wx = systemConfig('pay_wx');
  257. if ($pay_wx == 2) {
  258. $appid = env('WECHAT_MP.APPID');
  259. $new_secret = env('WECHAT_MP.SECRET');
  260. $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
  261. $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  262. } elseif ($pay_wx == 3) {
  263. $appid = env('WECHAT_TDYL.APPID');
  264. $new_secret = env('WECHAT_TDYL.SECRET');
  265. $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  266. $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  267. }
  268. $type = '2';
  269. $params = [
  270. 'order_no' => $_order['order_sn'],
  271. 'app_id' => $app_id,
  272. 'pay_channel' => 'wx_lite',
  273. 'pay_amt' => (string)$_order['order_price'],
  274. 'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题
  275. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题
  276. 'device_info' => [
  277. 'device_ip' => app('request')->ip()
  278. ],
  279. 'expend' => json_encode(['open_id' => $openid, 'wx_app_id' => $appid]),
  280. 'fee_mode' => 'I',
  281. 'notify_url' => $notify_url,
  282. 'pay_mode' => $pay_mode
  283. ];
  284. break;
  285. case 'ALI':
  286. case 'ali':
  287. $type = '1';
  288. // 天地博爱科技通道
  289. $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
  290. $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  291. $params = [
  292. 'order_no' => $_order['order_sn'],
  293. 'app_id' => $app_id,
  294. 'pay_channel' => 'alipay_qr',
  295. 'pay_amt' => (string)$_order['order_price'],
  296. 'goods_title' => strlen($title) > 64 ? mb_substr($title, 0, 64, 'utf-8') : $title,// 解决因为太长不能支付问题
  297. 'goods_desc' => strlen($title) > 42 ? mb_substr($title, 0, 127, 'utf-8') : $title,// 解决因为太长不能支付问题
  298. 'device_info' => [
  299. 'device_ip' => app('request')->ip()
  300. ],
  301. 'fee_mode' => 'I',
  302. 'notify_url' => $notify_url
  303. ];
  304. break;
  305. default:
  306. throw new ValidateException('请选择支付方式');
  307. break;
  308. }
  309. return $this->Payment_create_traits_a($params, $type, $key);
  310. }
  311. /**
  312. * @param $userinfo
  313. * @param $order_sn
  314. * @return mixed|string
  315. */
  316. public function getOrderInfo($userinfo, $order_sn)
  317. {
  318. $orderinfo = $this->dao->search(['order_sn' => $order_sn, 'uid' => $userinfo['uid']])->find();
  319. if (empty($orderinfo)) throw new ValidateException('订单不存在');
  320. $result = DouHuoMallFilmApiRequest::getOrderInfo($order_sn);
  321. if (!empty($result) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
  322. $plat_orderinfo = $result['data'];
  323. $plat_orderinfo['order_sn'] = $plat_orderinfo['third_order'];
  324. $plat_orderinfo['sched_seat'] = base64_encode(json_encode($plat_orderinfo['sched_seat'], JSON_FORCE_OBJECT));
  325. $plat_orderinfo['order_price'] = $orderinfo['order_price'];
  326. $plat_orderinfo['sched_seat'] = json_decode($orderinfo['sched_seat'], true);
  327. $plat_orderinfo['cinema_film'] = Db::name('movie_cinema_sched')
  328. ->where('film_sign', $orderinfo['film_sign'])
  329. ->where(['relation_id' => $orderinfo['relation_id'], 'sched_sign' => $orderinfo['sched_sign']])
  330. ->field('cinema_sign,cinema_name,address,longitude,latitude,hall_sign,hall_name,film_sign,film_name,show_date,show_time')
  331. ->find();
  332. $plat_orderinfo['cinema_film']['show_date'] = date('Y-m-d', $plat_orderinfo['cinema_film']['show_date']);
  333. $plat_orderinfo['cinema_film']['cover_img'] = Db::name('movie_film')->where('film_sign', $orderinfo['film_sign'])->value('cover_img');
  334. unset($plat_orderinfo['plat_order']);
  335. unset($plat_orderinfo['third_order']);
  336. return $plat_orderinfo;
  337. }
  338. throw new ValidateException('订单不存在');
  339. }
  340. /**
  341. * @return array
  342. * @throws \think\db\exception\DataNotFoundException
  343. * @throws \think\db\exception\DbException
  344. * @throws \think\db\exception\ModelNotFoundException
  345. */
  346. public function getLocalMovieCity()
  347. {
  348. $city_name = [];
  349. $city = Db::name('movie_city')->field('city_sign,city_name,initial')->where('is_show', 1)->order('id asc')->select();
  350. foreach ($city as $key => $value) {
  351. $city_name[$value['initial']][] = ['city_sign' => $value['city_sign'], 'city_name' => $value['city_name']];
  352. }
  353. $initial = !empty($city) ? array_values(array_column($city->toArray(), 'initial', 'initial')) : [];
  354. return compact('city_name', 'initial');
  355. }
  356. /**
  357. * 获取pv、养老金、售价、积分
  358. *
  359. * @param $cost_price
  360. * @return array
  361. */
  362. public static function getPvYanglaojinScore($cost_price)
  363. {
  364. $premium = round($cost_price * self::premium_ratio, 2);
  365. $cost_price = bcadd((string)$cost_price, (string)$premium, 2);
  366. $pv = $gongxian = $score = bcmul((string)$premium, self::pv_ratio, 2);
  367. $yanglaojin = bcmul((string)$premium, self::yanglaojin_ratio, 2);
  368. return compact('premium', 'cost_price', 'pv', 'yanglaojin', 'gongxian', 'score');
  369. }
  370. /**
  371. * 计算佣金分佣奖励
  372. *
  373. * @param $pay_type
  374. * @param $order_sn
  375. * @param $post_data
  376. * @return void
  377. * @throws \think\db\exception\DataNotFoundException
  378. * @throws \think\db\exception\DbException
  379. * @throws \think\db\exception\ModelNotFoundException
  380. */
  381. public function updateMovieOrderAndcalculationCommissionDividendAward($pay_type, $order_sn, $post_data)
  382. {
  383. $orderinfo = $this->dao->search(['order_sn' => $order_sn])->find();
  384. if ($orderinfo) throw new ValidateException('订单不存在');
  385. Db::startTrans();
  386. $orderinfo->paid = 1;
  387. $orderinfo->pay_time = time();
  388. $orderinfo->pay_type = $pay_type;
  389. $orderinfo->status = 1;
  390. $orderinfo->channel_trade_no = $post_data['id'];
  391. $orderinfo->pay_open_id = $post_data['expend']['open_id'];
  392. $orderinfo->update_time = time();
  393. // 支付方式 1支付宝 2微信
  394. if ($pay_type == 1) {
  395. $orderinfo->alipay_no = $post_data['out_trans_id'];
  396. }
  397. if ($pay_type == 2) {
  398. $orderinfo->weixin_no = $post_data['out_trans_id'];
  399. }
  400. $res = $orderinfo->save();
  401. if ($res) {
  402. $confirmOrder = DouHuoMallFilmApiRequest::confirmOrder($orderinfo['order_sn'], $orderinfo['price']);
  403. if (!empty($confirmOrder) && isset($confirmOrder['code']) && ($confirmOrder['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
  404. // 计算佣金分红奖励
  405. $this->calculationCommissionDividendAward();
  406. // 提交事务
  407. Db::commit();
  408. } else {
  409. Db::name('log')->insert(['data' => '电影票订单支付回调向【微唯宝】--- 告知电影订单已支付失败,订单编号:' . $order_sn]);
  410. // 回滚事务
  411. Db::rollback();
  412. }
  413. } else {
  414. Db::name('log')->insert(['data' => '汇付电影票订单支付回调--- 更新电影订单表失败,订单编号:' . $order_sn]);
  415. // 回滚事务
  416. Db::rollback();
  417. }
  418. }
  419. private function calculationCommissionDividendAward()
  420. {
  421. //商家让利部分的拆分
  422. $ylj_pri = bcmul($concession_pri, 0.3, 2); // 让利部分30%给消费者做养老金
  423. $pv = bcmul($concession_pri, 0.35, 2); // 35%做业绩PV分配
  424. //分配养老金给消费者
  425. $ylj_amount_mine = $user_data['annuity'] + $ylj_pri;
  426. //分配积分和贡献值给消费者
  427. $con = $user_data['contribute'] + $pv;
  428. $score = $user_data['score'] + $pv;
  429. // 让利部分30%给消费者做养老金{$ylj_pri}
  430. $this->bill_user_log($user_data['uid'], $ylj_pri, $store_order_data['order_id'], 5, $group_order['group_order_sn'], '购买商贸区商品获得养老金' . $ylj_pri, $store_order_data['mer_id'], 0);
  431. // @todo 消费者购买商品赠送PV等值的积分和贡献值
  432. // 贡献值
  433. // $this->con_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送贡献值");
  434. // 积分
  435. $this->score_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送积分");
  436. // @todo ------------PV业绩100%分配如下------------------
  437. if ($user_data['spread_uid'] != 0) {
  438. //查询下单用户上级
  439. $spread_data = Db::name('user')->where('uid', $user_data['spread_uid'])->find();
  440. $rate = static::getUserGroupRate($spread_data['user_group']);
  441. if ($spread_data['user_group'] > 1) {
  442. $ssf = 0;//变量
  443. $yj_amount_90 = 0;//90%的佣金
  444. // 业务员
  445. if ($spread_data['user_group'] == 2) {
  446. $ssf = bcmul($pv, $rate, 2);
  447. $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
  448. $score = $spread_data['score'] + bcmul($pv, $rate, 2);
  449. $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
  450. $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
  451. $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
  452. $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
  453. $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
  454. } else if ($spread_data['user_group'] == 3) {
  455. $ssf = bcmul($pv, $rate, 2);
  456. $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
  457. $score = $spread_data['score'] + bcmul($pv, $rate, 2);
  458. $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
  459. $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
  460. $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
  461. $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
  462. $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
  463. // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
  464. } else if ($spread_data['user_group'] == 4) {
  465. $ssf = bcmul($pv, $rate, 2);
  466. $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
  467. $score = $spread_data['score'] + bcmul($pv, $rate, 2);
  468. $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
  469. $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
  470. $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
  471. $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
  472. $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
  473. //Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
  474. } else if ($spread_data['user_group'] == 5) {
  475. $ssf = bcmul($pv, $rate, 2);
  476. $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
  477. $score = $spread_data['score'] + bcmul($pv, $rate, 2);
  478. // $yj_amount = $spread_data['brokerage_price'] + round($pv * $rate,2);
  479. $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
  480. $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
  481. $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
  482. $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
  483. $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
  484. // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
  485. } else if ($spread_data['user_group'] == 6) {
  486. $ssf = bcmul($pv, $rate, 2);
  487. $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
  488. $score = $spread_data['score'] + bcmul($pv, $rate, 2);
  489. $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
  490. $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
  491. $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
  492. $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
  493. $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
  494. // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
  495. } else if ($spread_data['user_group'] == 7) {
  496. $ssf = bcmul($pv, $rate, 2);
  497. $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
  498. $score = $spread_data['score'] + bcmul($pv, $rate, 2);
  499. $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
  500. $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
  501. $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
  502. $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
  503. $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
  504. // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
  505. }
  506. //贡献值
  507. $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "商贸区商品赠送贡献值");
  508. //积分
  509. $this->score_log($spread_data['uid'], $ssf, $store_order_data['order_id'], 12, "商贸区商品赠送积分");
  510. //推广佣金
  511. $this->bill_user_log($spread_data['uid'], $yj_amount_90, $store_order_data['order_id'], 3, $group_order['group_order_sn'], '推广获得佣金' . $yj_amount_90, $store_order_data['mer_id'], 0);
  512. //养老金
  513. $this->bill_user_log($spread_data['uid'], bcmul($pv, 0.05, 2), $store_order_data['order_id'], 5, $group_order['group_order_sn'], '推广获得养老金' . round($pv * 0.05, 2), $store_order_data['mer_id'], 0);
  514. }
  515. //普通用户推广人
  516. if ($spread_data['user_group'] == 1) {
  517. //给推广者分配佣金
  518. $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
  519. $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
  520. $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
  521. $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
  522. $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
  523. //Db::name('user')->where('uid',$spread_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]);
  524. $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
  525. $score = $spread_data['score'] + bcmul($pv, $rate, 2);
  526. //贡献值和积分
  527. // Db::name('user')->where('uid',$spread_data['uid'])->update(["contribute"=>$con,"score"=>$score]);
  528. //推广佣金
  529. $this->bill_user_log($spread_data['uid'], $yj_amount_90, $store_order_data['order_id'], 3, $group_order['group_order_sn'], '推广获得佣金' . $yj_amount_90, $store_order_data['mer_id'], 0);
  530. // 贡献值
  531. $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "推广商贸区商品赠送贡献值");
  532. // 积分
  533. $this->score_log($spread_data['uid'], bcmul($pv, $rate, 2), $store_order_data['order_id'], 12, "推广商贸区商品赠送积分");
  534. }
  535. }
  536. //锁客收益
  537. if ($user_data['mer_id'] != 0) {
  538. $merchant_data = Db::name('merchant')->where('mer_id', $user_data['mer_id'])->find();
  539. $merchant_user_data = Db::name('user')->where('uid', $merchant_data['uid'])->find();
  540. if (!empty($merchant_user_data)) {
  541. //给推广者分配佣金
  542. $yj_amount_90 = bcmul($pv, 0.05, 2) * 0.9;
  543. $fgj_amount_10 = bcmul($pv, 0.05, 2) * 0.1;//推广者的佣金抽10%到个人复购金
  544. $yj_amount = $merchant_user_data['brokerage_price'] + $yj_amount_90;
  545. $fgj_amount = $merchant_user_data['fugou'] + $fgj_amount_10;
  546. $this->fugou_user_log($merchant_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
  547. //推广佣金
  548. $this->bill_user_log($merchant_data['uid'], $yj_amount_90, $store_order_data['order_id'], 3, $group_order['group_order_sn'], '推广获得佣金' . $yj_amount_90, $store_order_data['mer_id'], 0);
  549. }
  550. /** @var OrderMerchantRepository $orderMerchantRepository */
  551. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  552. $jdAndGonxianConfig = $orderMerchantRepository->getMerchantContribution($store_order_data['extension_two']);
  553. //商户获得贡献值
  554. if ($concession_pri >= 0.01) {
  555. $gonxian = bcmul($concession_pri, $jdAndGonxianConfig['gonxian'], 2);
  556. $gongxian_data = [
  557. "uid" => $merchant_data["uid"],
  558. "mer_id" => $user_data['mer_id'],
  559. "pv" => $pv,
  560. "number" => $gonxian,
  561. "addtime" => time(),
  562. "status" => -1,
  563. "order_type" => 2,
  564. "order_id" => $store_order_data['order_id'],
  565. "mark" => "锁客商家获得贡献值",
  566. "desc" => '',
  567. "surplus" => $gonxian,
  568. "type" => 1
  569. ];
  570. Db::name("user_sign_gongxian")->insert($gongxian_data);//添加记录
  571. } else {
  572. Db::name('log')->insert(['data' => '订单号:' . $store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,贡献值低于0.01无法入库 特此记录!']);
  573. }
  574. //商户获得京豆
  575. if ($concession_pri >= 0.01) {
  576. $jd = bcmul($concession_pri, $jdAndGonxianConfig['jd'], 2);
  577. $jd_data = [
  578. "uid" => $merchant_data["uid"],
  579. "mer_id" => $user_data['mer_id'],
  580. "number" => $jd,
  581. "addtime" => time(),
  582. "status" => -1,
  583. "order_type" => 2,
  584. "order_id" => $store_order_data['order_id'],
  585. "mark" => "锁客商家获得京豆",
  586. "desc" => '',
  587. "surplus" => $jd,
  588. "type" => 1
  589. ];
  590. Db::name("user_sign_jingdou")->insert($jd_data);//添加记录
  591. } else {
  592. Db::name('log')->insert(['data' => '订单号:' . $store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,京豆低于0.01无法入库 特此记录!']);
  593. }
  594. }
  595. }
  596. /**
  597. * 订单列表
  598. *
  599. * @param $userinfo
  600. * @param $page
  601. * @param $limit
  602. * @param $type
  603. * @return array
  604. * @throws \think\db\exception\DataNotFoundException
  605. * @throws \think\db\exception\DbException
  606. * @throws \think\db\exception\ModelNotFoundException
  607. */
  608. public function getOrderList($userinfo, $page, $limit, $type = -1)
  609. {
  610. $where['uid'] = $userinfo['uid'];
  611. switch ($type) {
  612. case 0:
  613. $where['status'] = [0];
  614. break;
  615. case 1:
  616. case 4:
  617. $where['status'] = [1, 4];
  618. break;
  619. case 2:
  620. case 3:
  621. $where['status'] = [2, 3];
  622. break;
  623. default:
  624. break;
  625. }
  626. $field = 'order_sn,order_price,city_name,area_name,cinema_name,address,hall_name,film_sign,film_name,show_date,show_time,sched_seat,number,status,create_time';
  627. $movie_order = $this->dao->search($where)
  628. ->when($page && $limit, function ($query) use ($page, $limit) {
  629. $query->page($page, $limit);
  630. })->order('order_id desc')->field([$field])->select()->toArray();
  631. foreach ($movie_order as $key => $value) {
  632. $movie_order[$key]['show_date'] = date('Y-m-d', $value['show_date']);
  633. $movie_order[$key]['sched_seat'] = json_decode($value['sched_seat'], true);
  634. $movie_order[$key]['cover_img'] = Db::name('movie_film')->where('film_sign', $value['film_sign'])->value('cover_img');
  635. }
  636. $count = $this->dao->search($where)->count();
  637. return compact('movie_order', 'count');
  638. }
  639. }