| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728 |
- <?php
- /**
- * @package merchant
- * @Author: Qinii
- * @Date: 2020/5/8
- */
- namespace app\common\repositories\movie;
- use app\common\dao\movie\order\MovieOrderDao;
- use app\common\model\movie\order\MovieOrder;
- use app\common\repositories\BaseRepository;
- use app\common\repositories\merchant\order\OrderMerchantRepository;
- use app\common\repositories\store\order\StoreOrderRepository;
- use app\traits\HuiPay;
- use crmeb\services\ApiResponseService;
- use think\exception\ValidateException;
- use think\facade\Db;
- /**
- * Class MovieRepository
- * @package app\common\repositories\movie
- * @author xaboy
- * @mixin MovieOrderDao
- */
- class MovieRepository extends BaseRepository
- {
- use HuiPay;
- protected $dao;
- const premium_ratio = 0.2;//溢价比例
- const yanglaojin_ratio = 0.3;
- const pv_ratio = 0.7;
- /**
- * 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 = '')
- {
- $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);
- $seat = [];
- $schedSeatList = (isset($result['code']) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) ? $result['data'] : [];
- foreach ($schedSeatList as $key => $value) {
- $tmpprice = [];
- foreach ($value['price'] as $pKey => $pValue) {
- $tmpprice[$pKey] = ['channel_type' => $pKey, 'price' => $pValue];
- }
- $channel_price = [];
- if (isset($tmpprice['P2'])) {
- $channel_price = $tmpprice['P2'];
- } elseif (isset($tmpprice['P1'])) {
- $channel_price = $tmpprice['P1'];
- } elseif (isset($tmpprice['P0'])) {
- $channel_price = $tmpprice['P0'];
- }
- unset($schedSeatList[$key]['price']);
- $pcYanglaojinGongxian = self::getPvYanglaojinScore($channel_price['price']);
- $schedSeatList[$key]['channel_sn'] = base64_encode(json_encode($channel_price, JSON_FORCE_OBJECT));
- $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; // 场次编码
- $seat[$value['rowNo']][] = $schedSeatList[$key];
- }
- if ($seat) ksort($seat);
- return array_values($seat);
- }
- /**
- * 锁座订单
- *
- * @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 = substr($storeOrder->getNewOrderId(), 0, 20);
- /** @var CinemaSchedRepository $cinemaSchedRepository */
- $cinemaSchedRepository = app()->make(CinemaSchedRepository::class);
- $sched = $cinemaSchedRepository->getCinemaSchedInfo($params['relation_id'], $params['sched_sign']);
- if (empty($sched)) throw new ValidateException('观影场次不存在');
- $channel_sn = json_decode(base64_decode($params['channel_sn']), true);
- if (empty($channel_sn) || !isset($channel_sn['channel_type']) || empty($channel_sn['channel_type']) || !isset($channel_sn['price'])
- || empty($channel_sn['price']) || json_last_error()) {
- throw new ValidateException('请选择观影场次');
- }
- $sched_seat = json_decode($params['sched_seat'], true);
- if (json_last_error()) throw new ValidateException('锁座下单失败');
- $order_price = bcmul((string)$channel_sn['price'], (string)count($sched_seat), 2);
- $submitOrder = DouHuoMallFilmApiRequest::submitOrder($userinfo->phone, $channel_sn['channel_type'], $params['sched_sign'], array_column($sched_seat, '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' => $order_price,
- 'number' => count($sched_seat),
- 'order_price' => bcadd((string)$order_price, bcmul((string)$order_price, (string)self::premium_ratio, 2), 2),
- 'channel_type' => $channel_sn['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' => $params['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
- * @param $pay_type
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function confirmOrder($userinfo, $order_sn, $pay_type)
- {
- $orderinfo = $this->dao->search(['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('订单已支付');
- $res = $this->pay($pay_type, $userinfo['wechat_user_id'], $orderinfo, $orderinfo['film_name'], env('APP_URL') . "/api/hf_notify/movie", 'delay');
- Db::name('log')->insert(['data' => '汇付电影票订单支付--- 返回参数' . json_encode($res)]);
- if (isset($res['id'])) {
- $type = 0;
- if ($pay_type == 'wx') $type = 2;
- if (strtolower($pay_type) == 'ali') $type = 1;
- $orderinfo->pay_type = $type;
- $orderinfo->update_time = time();
- $orderinfo->save();
- return app('json')->success($res);
- }
- throw new ValidateException('支付失败');
- }
- /**
- * 支付
- *
- * @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':
- 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->search(['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)) {
- $plat_orderinfo = $result['data'];
- $plat_orderinfo['order_sn'] = $plat_orderinfo['third_order'];
- $plat_orderinfo['sched_seat'] = base64_encode(json_encode($plat_orderinfo['sched_seat'], JSON_FORCE_OBJECT));
- $plat_orderinfo['order_price'] = $orderinfo['order_price'];
- $plat_orderinfo['sched_seat'] = json_decode($orderinfo['sched_seat'], true);
- $plat_orderinfo['cinema_film'] = Db::name('movie_cinema_sched')
- ->where('film_sign', $orderinfo['film_sign'])
- ->where(['relation_id' => $orderinfo['relation_id'], 'sched_sign' => $orderinfo['sched_sign']])
- ->field('cinema_sign,cinema_name,address,longitude,latitude,hall_sign,hall_name,film_sign,film_name,show_date,show_time')
- ->find();
- $plat_orderinfo['cinema_film']['show_date'] = date('Y-m-d', $plat_orderinfo['cinema_film']['show_date']);
- $plat_orderinfo['cinema_film']['cover_img'] = Db::name('movie_film')->where('film_sign', $orderinfo['film_sign'])->value('cover_img');
- unset($plat_orderinfo['plat_order']);
- unset($plat_orderinfo['third_order']);
- return $plat_orderinfo;
- }
- 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');
- }
- /**
- * 计算佣金分佣奖励
- *
- * @param $pay_type
- * @param $order_sn
- * @param $post_data
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function updateMovieOrderAndcalculationCommissionDividendAward($pay_type, $order_sn, $post_data)
- {
- $orderinfo = $this->dao->search(['order_sn' => $order_sn])->find();
- if ($orderinfo) throw new ValidateException('订单不存在');
- Db::startTrans();
- $orderinfo->paid = 1;
- $orderinfo->pay_time = time();
- $orderinfo->pay_type = $pay_type;
- $orderinfo->status = 1;
- $orderinfo->channel_trade_no = $post_data['id'];
- $orderinfo->pay_open_id = $post_data['expend']['open_id'];
- $orderinfo->update_time = time();
- // 支付方式 1支付宝 2微信
- if ($pay_type == 1) {
- $orderinfo->alipay_no = $post_data['out_trans_id'];
- }
- if ($pay_type == 2) {
- $orderinfo->weixin_no = $post_data['out_trans_id'];
- }
- $res = $orderinfo->save();
- if ($res) {
- $confirmOrder = DouHuoMallFilmApiRequest::confirmOrder($orderinfo['order_sn'], $orderinfo['price']);
- if (!empty($confirmOrder) && isset($confirmOrder['code']) && ($confirmOrder['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
- // 计算佣金分红奖励
- $this->calculationCommissionDividendAward();
- // 提交事务
- Db::commit();
- } else {
- Db::name('log')->insert(['data' => '电影票订单支付回调向【微唯宝】--- 告知电影订单已支付失败,订单编号:' . $order_sn]);
- // 回滚事务
- Db::rollback();
- }
- } else {
- Db::name('log')->insert(['data' => '汇付电影票订单支付回调--- 更新电影订单表失败,订单编号:' . $order_sn]);
- // 回滚事务
- Db::rollback();
- }
- }
- private function calculationCommissionDividendAward()
- {
- //商家让利部分的拆分
- $ylj_pri = bcmul($concession_pri, 0.3, 2); // 让利部分30%给消费者做养老金
- $pv = bcmul($concession_pri, 0.35, 2); // 35%做业绩PV分配
- //分配养老金给消费者
- $ylj_amount_mine = $user_data['annuity'] + $ylj_pri;
- //分配积分和贡献值给消费者
- $con = $user_data['contribute'] + $pv;
- $score = $user_data['score'] + $pv;
- // 让利部分30%给消费者做养老金{$ylj_pri}
- $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);
- // @todo 消费者购买商品赠送PV等值的积分和贡献值
- // 贡献值
- // $this->con_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送贡献值");
- // 积分
- $this->score_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送积分");
- // @todo ------------PV业绩100%分配如下------------------
- if ($user_data['spread_uid'] != 0) {
- //查询下单用户上级
- $spread_data = Db::name('user')->where('uid', $user_data['spread_uid'])->find();
- $rate = static::getUserGroupRate($spread_data['user_group']);
- if ($spread_data['user_group'] > 1) {
- $ssf = 0;//变量
- $yj_amount_90 = 0;//90%的佣金
- // 业务员
- if ($spread_data['user_group'] == 2) {
- $ssf = bcmul($pv, $rate, 2);
- $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
- $score = $spread_data['score'] + bcmul($pv, $rate, 2);
- $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
- $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
- $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
- $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
- $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
- } else if ($spread_data['user_group'] == 3) {
- $ssf = bcmul($pv, $rate, 2);
- $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
- $score = $spread_data['score'] + bcmul($pv, $rate, 2);
- $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
- $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
- $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
- $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
- $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
- // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
- } else if ($spread_data['user_group'] == 4) {
- $ssf = bcmul($pv, $rate, 2);
- $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
- $score = $spread_data['score'] + bcmul($pv, $rate, 2);
- $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
- $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
- $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
- $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
- $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
- //Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
- } else if ($spread_data['user_group'] == 5) {
- $ssf = bcmul($pv, $rate, 2);
- $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
- $score = $spread_data['score'] + bcmul($pv, $rate, 2);
- // $yj_amount = $spread_data['brokerage_price'] + round($pv * $rate,2);
- $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
- $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
- $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
- $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
- $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
- // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
- } else if ($spread_data['user_group'] == 6) {
- $ssf = bcmul($pv, $rate, 2);
- $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
- $score = $spread_data['score'] + bcmul($pv, $rate, 2);
- $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
- $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
- $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
- $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
- $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
- // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
- } else if ($spread_data['user_group'] == 7) {
- $ssf = bcmul($pv, $rate, 2);
- $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
- $score = $spread_data['score'] + bcmul($pv, $rate, 2);
- $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
- $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
- $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
- $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
- $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
- // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
- }
- //贡献值
- $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "商贸区商品赠送贡献值");
- //积分
- $this->score_log($spread_data['uid'], $ssf, $store_order_data['order_id'], 12, "商贸区商品赠送积分");
- //推广佣金
- $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);
- //养老金
- $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);
- }
- //普通用户推广人
- if ($spread_data['user_group'] == 1) {
- //给推广者分配佣金
- $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
- $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
- $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
- $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
- $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
- //Db::name('user')->where('uid',$spread_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]);
- $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
- $score = $spread_data['score'] + bcmul($pv, $rate, 2);
- //贡献值和积分
- // Db::name('user')->where('uid',$spread_data['uid'])->update(["contribute"=>$con,"score"=>$score]);
- //推广佣金
- $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);
- // 贡献值
- $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "推广商贸区商品赠送贡献值");
- // 积分
- $this->score_log($spread_data['uid'], bcmul($pv, $rate, 2), $store_order_data['order_id'], 12, "推广商贸区商品赠送积分");
- }
- }
- //锁客收益
- if ($user_data['mer_id'] != 0) {
- $merchant_data = Db::name('merchant')->where('mer_id', $user_data['mer_id'])->find();
- $merchant_user_data = Db::name('user')->where('uid', $merchant_data['uid'])->find();
- if (!empty($merchant_user_data)) {
- //给推广者分配佣金
- $yj_amount_90 = bcmul($pv, 0.05, 2) * 0.9;
- $fgj_amount_10 = bcmul($pv, 0.05, 2) * 0.1;//推广者的佣金抽10%到个人复购金
- $yj_amount = $merchant_user_data['brokerage_price'] + $yj_amount_90;
- $fgj_amount = $merchant_user_data['fugou'] + $fgj_amount_10;
- $this->fugou_user_log($merchant_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
- //推广佣金
- $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);
- }
- /** @var OrderMerchantRepository $orderMerchantRepository */
- $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
- $jdAndGonxianConfig = $orderMerchantRepository->getMerchantContribution($store_order_data['extension_two']);
- //商户获得贡献值
- if ($concession_pri >= 0.01) {
- $gonxian = bcmul($concession_pri, $jdAndGonxianConfig['gonxian'], 2);
- $gongxian_data = [
- "uid" => $merchant_data["uid"],
- "mer_id" => $user_data['mer_id'],
- "pv" => $pv,
- "number" => $gonxian,
- "addtime" => time(),
- "status" => -1,
- "order_type" => 2,
- "order_id" => $store_order_data['order_id'],
- "mark" => "锁客商家获得贡献值",
- "desc" => '',
- "surplus" => $gonxian,
- "type" => 1
- ];
- Db::name("user_sign_gongxian")->insert($gongxian_data);//添加记录
- } else {
- Db::name('log')->insert(['data' => '订单号:' . $store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,贡献值低于0.01无法入库 特此记录!']);
- }
- //商户获得京豆
- if ($concession_pri >= 0.01) {
- $jd = bcmul($concession_pri, $jdAndGonxianConfig['jd'], 2);
- $jd_data = [
- "uid" => $merchant_data["uid"],
- "mer_id" => $user_data['mer_id'],
- "number" => $jd,
- "addtime" => time(),
- "status" => -1,
- "order_type" => 2,
- "order_id" => $store_order_data['order_id'],
- "mark" => "锁客商家获得京豆",
- "desc" => '',
- "surplus" => $jd,
- "type" => 1
- ];
- Db::name("user_sign_jingdou")->insert($jd_data);//添加记录
- } else {
- Db::name('log')->insert(['data' => '订单号:' . $store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,京豆低于0.01无法入库 特此记录!']);
- }
- }
- }
- /**
- * 订单列表
- *
- * @param $userinfo
- * @param $page
- * @param $limit
- * @param $type
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getOrderList($userinfo, $page, $limit, $type = -1)
- {
- $where['uid'] = $userinfo['uid'];
- switch ($type) {
- case 0:
- $where['status'] = [0];
- break;
- case 1:
- case 4:
- $where['status'] = [1, 4];
- break;
- case 2:
- case 3:
- $where['status'] = [2, 3];
- break;
- default:
- break;
- }
- $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';
- $movie_order = $this->dao->search($where)
- ->when($page && $limit, function ($query) use ($page, $limit) {
- $query->page($page, $limit);
- })->order('order_id desc')->field([$field])->select()->toArray();
- foreach ($movie_order as $key => $value) {
- $movie_order[$key]['show_date'] = date('Y-m-d', $value['show_date']);
- $movie_order[$key]['sched_seat'] = json_decode($value['sched_seat'], true);
- $movie_order[$key]['cover_img'] = Db::name('movie_film')->where('film_sign', $value['film_sign'])->value('cover_img');
- }
- $count = $this->dao->search($where)->count();
- return compact('movie_order', 'count');
- }
- }
|