123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- <?php
- namespace app\fastshop\widget;
- use think\facade\Cookie;
- class Order{
-
- public function saveOrder(array $data){
- $order['order_no'] = order_no();
- $order['user_id'] = $data['user_id'];
- $order['sale_id'] = $data['sale_id'];
- $order['member_miniapp_id'] = $data['member_miniapp_id'];
- $order['payment_id'] = $data['payment_id'];
- $order['real_amount'] = $data['real_amount'];
- $order['real_freight'] = $data['real_freight'];
- $order['order_amount'] = $data['order_amount'];
- $order['express_name'] = $data['express_name'];
- $order['express_phone'] = $data['express_phone'];
- $order['express_address'] = $data['express_address'];
- $order['paid_at'] = $data['paid_at'];
- $order['is_fusion'] = $data['is_fusion'];
- if($data['paid_at'] == 1){
- $order['paid_time'] = time();
- $order['paid_no'] = $order['order_no'];
- }
- $order['status'] = 0;
- $order['is_del'] = 0;
- $order['express_status'] = 0;
- $order['order_starttime'] = time();
- $rel = model('fastshop/Order')->insertGetId($order);
- return empty($rel) ? false : $order['order_no'];
- }
-
- public function realAmount(array $item,$miniapp_id){
- $fare = model('fastshop/fare')->get(['member_miniapp_id' => $miniapp_id]);
- $real_amount = $item['sale_price'];
- $real_freight = 0;
- $weight = $item['weight'];
- if($weight <= $fare['first_weight'] || 0 == $fare['second_weight']){
- $real_freight = $fare['first_price'];
- }else{
- $weight = $weight - $fare['second_weight'];
- $real_freight = $fare['first_price'] + ceil($weight/$fare['second_weight']) * $fare['second_price'];
- }
- $data['real_amount'] = money($real_amount);
- $data['real_freight'] = money($real_freight);
- $data['order_amount'] = money($real_freight+$real_amount);
- return $data;
- }
-
- public function gift(array $gift){
- $gift_id = array_column($gift,'item_id');
- $list = model('fastshop/item')->field('id,name,img,imgs,content,weight')->whereIn('id',$gift_id)->select()->toArray();
- $gift_data = [];
- foreach ($gift as $k => $v) {
- $gift_value['item_id'] = $v['item_id'];
- $gift_value['sale_price'] = money($v['sale_price']/100);
- $gift_value['market_price'] = money($v['market_price']/100);
- foreach ($list as $value) {
- if ($v['item_id'] == $value['id']) {
- $gift_data[$k] = array_merge($value,$gift_value);
- $gift_data[$k]['img'] = $value['img']."?x-oss-process = style/auto";
- $gift_data[$k]['imgs'] = json_decode($value['imgs'],true);
- $gift_data[$k]['content'] = $value['content'];
- }
- }
- }
- return $gift_data;
- }
-
- public function userGift($array,$uid){
- $where_entrust['member_miniapp_id'] = $array['member_miniapp_id'];
- $where_entrust['item_id'] = $array['item_id'];
- $where_entrust['is_rebate'] = 0;
- $where_entrust['is_under'] = 0;
- return model('EntrustList')->where($where_entrust)->where(['user_id' => $uid])->find();
- }
-
- public function goodGift($array,$uid,$config){
- $where_entrust['member_miniapp_id'] = $array['member_miniapp_id'];
- $where_entrust['item_id'] = $array['item_id'];
- $where_entrust['is_rebate'] = 0;
- $where_entrust['is_under'] = 0;
-
- $entrust = [];
- if($config['is_priority'] == 1){
- $level = model('SystemUserLevel')->field('parent_id')->where(['user_id' => $uid,'level' => 1])->find();
- if (!empty($level)) {
- $entrust = model('EntrustList')->where($where_entrust)->where(['user_id' => $level->parent_id])->order('id asc')->find();
- }
- }
-
- if (empty($entrust)) {
- $entrust = model('EntrustList')->where($where_entrust)->order('id asc')->find();
- }
- return $entrust;
- }
-
-
- public function rebate(int $miniapp_id,$order_no,int $item_id,int $uid,$config){
- $item = [];
- if(empty($order_no)){
- $item[] = $item_id;
- }else{
- $order = model('OrderCache')->field('item_id,order_no,entrust,fusion_state,gift')->where(['order_no' => $order_no])->find();
- if(empty($order)){
- return;
- }
- if($order->order->is_fusion){
- $item = array_column(json_decode($order->gift,true),'item_id');
- }else{
- $item[] = $order->item_id;
- }
- }
-
- foreach ($item as $id) {
- $where_entrust['member_miniapp_id'] = $miniapp_id;
- $where_entrust['item_id'] = $id;
- $where_entrust['is_rebate'] = 0;
-
- if(empty($order_no) && $uid > 0){
- $entrust = self::userGift($where_entrust,$uid);
- }else{
- $entrust = self::goodGift($where_entrust,$uid,$config);
- }
- $is_diy = empty($order_no) ? 1 : 0;
- if (!empty($entrust)){
-
- $order_amount = $entrust->is_fusion ? $entrust->entrust_price : $entrust->entrust_price/2;
- $cash_fee = abs($entrust['entrust_price']*($config->profit/100));
- $income = $cash_fee + $order_amount;
-
- if($order_amount > 0){
- $shop_money = intval($cash_fee*($config->shopping/100));
- $due_money = intval($cash_fee-$shop_money+$order_amount);
- model('Bank')->due_up($miniapp_id,$entrust->user_id,$due_money,$shop_money);
- model('Bank')->isProfit($entrust->user_id,money($cash_fee/100));
- $income = $cash_fee + $order_amount;
- model('BankLogs')->add($miniapp_id,$entrust->user_id,$income,money($income/100).'成交积分');
- }
- model('EntrustList')->where(['id' => $entrust->id])->update(['is_diy'=> $is_diy,'is_rebate'=>1,'is_under'=>1,'update_time'=>time(),'rebate' => $income]);
- model('entrust')->where(['item_id' => $item_id])->setDec('gite_count',1);
- }
- }
- return empty($item_id) ? false : true;
- }
-
- public function pointPay(int $miniapp_id,int $uid,float $cash_fee,$config){
- $payment_point = $config->payment_point/100;
- $point = intval(($cash_fee*$payment_point)*100);
- $info = model('Bank')->where(['member_miniapp_id' => $miniapp_id,'user_id' => $uid])->find();
- if(empty($info)){
- return;
- }
- if($config->payment_type == 1){
- $info->due_money = ['dec',$point];
- $info->money = ['dec',$point];
- }else{
- $info->shop_money = ['dec',$point];
- $info->money = ['dec',$point];
- }
- $info->update_time = time();
- return $info->save();
- }
-
- public function shopPointPay(int $miniapp_id,int $uid,float $cash_fee){
- $config = model('Config')->get(['member_miniapp_id' => $miniapp_id]);
- $payment_point = $config['payment_point_shop']/100;
- $point = intval(($cash_fee*$payment_point)*100);
- $info = model('Bank')->where(['member_miniapp_id'=>$miniapp_id,'user_id' => $uid])->find();
- if(empty($info)){
- return;
- }
- if($config['payment_type_shop'] == 1){
- $info->due_money = ['dec',$point];
- $info->money = ['dec',$point];
- }else{
- $info->shop_money = ['dec',$point];
- $info->money = ['dec',$point];
- }
- $info->update_time = time();
- return $info->save();
- }
- }
|