diff --git a/api/controllers/Welcome.php b/api/controllers/Welcome.php index b80b45fe..74a95a5c 100755 --- a/api/controllers/Welcome.php +++ b/api/controllers/Welcome.php @@ -11,5 +11,11 @@ class Welcome extends CI_Controller { } public function test(){ + $oid = $this->input->get('oid'); + $this->load->library('qyrobot'); + $params['test'] = 1; + $qy = new Qyrobot($params); + $res = $qy->deposit_notify_v3($oid); + var_dump($res);exit; } } diff --git a/common/libraries/Qyrobot.php b/common/libraries/Qyrobot.php index 487595bf..0a5ba642 100644 --- a/common/libraries/Qyrobot.php +++ b/common/libraries/Qyrobot.php @@ -419,4 +419,254 @@ class Qyrobot{ $result = json_decode($res,true); return $result; } + /** + * 新订单支付后推送消息 + * @param $oid + * @param int $type type=0 当天 type=1 补报 + * @param string $date 日期type=1必填 + * @return mixed + */ + public function deposit_notify_v3($oid, $type=0, $date=''){ + $this->ci->load->model('receiver/order/receiver_orders_v2_model'); + $this->ci->load->model("biz/biz_model"); + $this->ci->load->model('area_model'); + $this->ci->load->model('auto/auto_brand_model'); + $this->ci->load->model('auto/auto_series_model'); + $this->ci->load->model('auto/auto_attr_model'); + + $this->ci->load->model('app/liche/app_liche_orders_model'); + $this->ci->load->model('app/liche/app_liche_orders_model'); + $this->ci->load->model('app/licheb/app_licheb_users_model'); + $this->ci->load->model('app/licheb/app_licheb_channel_biz_model'); + + $order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$order_row){ + return false; + } + $biz_row = $this->ci->biz_model->get(['id'=>$order_row['biz_id']]); + if($biz_row['type']==3){ + $channel_users = $this->ci->app_licheb_channel_biz_model->select(['biz_id'=>$biz_row['id']],'','','','uid'); + $user_ids = array_column($channel_users,'uid'); + $user_ids_str = implode(',',$user_ids); + $user_info = ''; + if($user_ids_str && $user_ids){ + $where = [ + 'group_id' => 4, + 'status' => 1, + "id in ($user_ids_str)" => null + ]; + $users = $this->ci->app_licheb_users_model->select($where,'id desc',1,10,'uname,biz_id'); //渠道经理 + if($users){ + $user_info = implode(' ',array_column($users,'uname')); + }else{ //获取城市 + $city_row = $this->ci->area_model->get(['city_id'=>$biz_row['city_id']]); + $user_info = $city_row['city_name']; + } + } + $biz_info = "{$user_info}渠道 {$biz_row['biz_name']}"; + }elseif($biz_row['type']==4){ //合伙店 + $biz_info = "合伙店 {$biz_row['biz_name']}"; + }else{ + $user = $this->ci->app_licheb_users_model->get(['id'=>$order_row['sale_id']],'uname'); //获取销售员 + $biz_info = "{$biz_row['biz_name']} {$user['uname']}"; + } + $brand_row = $this->ci->auto_brand_model->get(['id'=>$order_row['brand_id']],'name'); + $series_row = $this->ci->auto_series_model->get(['id'=>$order_row['s_id']],'name'); + $attr_arr = [$order_row['v_id'], $order_row['cor_id']]; + $attr = $this->ci->auto_attr_model->get_map_by_ids($attr_arr, 'id,title'); + $v_name = isset($attr[$order_row['v_id']]) ? $attr[$order_row['v_id']][0]['title'] : ''; + $cor_name = isset($attr[$order_row['cor_id']]) ? $attr[$order_row['cor_id']][0]['title'] : ''; + $car_info = "{$brand_row['name']} {$series_row['name']} {$v_name} {$cor_name}"; + + $min_price = 100; + if($type){ + if(!$date){ + return false; + } + $today_s_time = date('Y-m-d 00:00:00',strtotime($date)); + $today_e_time = date('Y-m-d 23:59:59',strtotime($date)); + $month_s_time = date('Y-m-01 00:00:00',strtotime($date)); + $month_e_time = date('Y-m-t 23:59:59',strtotime($date)); + }else{ + $today_s_time = date('Y-m-d 00:00:00'); + $today_e_time = date('Y-m-d H:i:s'); + $month_s_time = date('Y-m-01 00:00:00'); + $month_e_time = date('Y-m-t H:i:s'); + } + + $sql = "select brand_id,count(a.o_id) as total from (select o_id,min(pay_time) as pay_time from lc_app_liche_orders + where o_id>=10000 and status=1 and pid!=0 and pay_price>0 and pay_time!='0000-00-00 00:00:00' and type <> 4 and pay_price>{$min_price} group by o_id order by o_id desc) as a + left join lc_receiver_orders_v2 as b on a.o_id=b.id + where a.pay_time>='{$today_s_time}' and a.pay_time<='{$today_e_time}' group by b.brand_id"; + $today_rows = $this->ci->db->query($sql)->row_array(); + $today_count = 0; + $today_info = []; + if($today_rows){ + foreach ($today_rows as $key => $val) { + $today_count += $val['total']; + $row = $this->auto_brand_model->get(['id'=>$val['brand_id']],'name'); + $today_info[] = [ + 'brand_name' => $row['name'], + 'num' => $val['total'] + ]; + } + } + + $sql = "select brand_id,count(a.o_id) as total from (select o_id,min(pay_time) as pay_time from lc_app_liche_orders + where o_id>=10000 and status=1 and pid!=0 and pay_price>0 and pay_time!='0000-00-00 00:00:00' and type <> 4 and pay_price>{$min_price} group by o_id order by o_id desc) as a + left join lc_receiver_orders_v2 as b on a.o_id=b.id + where a.pay_time>='{$month_s_time}' and a.pay_time<='{$month_e_time}' group by b.brand_id"; + $month_rows = $this->ci->db->query($sql)->row_array(); + $month_count = 0; + $month_info = []; + if($month_rows){ + foreach ($today_rows as $key => $val) { + $month_count += $val['total']; + $row = $this->auto_brand_model->get(['id'=>$val['brand_id']],'name'); + $month_info[] = [ + 'brand_name' => $row['name'], + 'num' => $val['total'] + ]; + } + } + $day = date('d日',strtotime($date)); + $m_day = date('m月d日',strtotime($date)); + $month = date('m',strtotime($date)); + $month_show = $month==date('m') ? '本月' : $month.'月'; + //发送飞书 + $info = [ + 'biz_info' => $biz_info, + 'day' => $day, + 'car_info' => $car_info, + 'owner_name' => $order_row['owner_name'], + 'm_day' => $m_day, + 'today_count' => $today_count, + 'month_show' => $month_show, + 'month_count' => $month_count + ]; + $send_msg = $this->fbook_formart_v3($info,$type,$today_info,$month_info); + $result = $this->send_fb($send_msg); + return $result; + } + + public function fbook_formart_v3($info,$type,$today_info,$month_info){ + + $title = $type ? '🎉🎉🎉 **喜讯-补报** 🎉🎉🎉' : '🎉🎉🎉 **喜讯** 🎉🎉🎉'; + $header = [ + [ + 'tag' => 'text', + 'text' => ' 恭喜', + ], + [ + 'tag' => 'a', + 'text' => $info['biz_info'], + ], + [ + 'tag' => 'text', + 'text' => '成交', + ], + [ + 'tag' => 'a', + 'text' => $info['car_info']."({$info['owner_name']})", + ], + [ + 'tag' => 'text', + 'text' => '一台。', + ], + ]; + $content[] = $header; + $content[] = [ + [ + 'tag' => 'text', + 'text' => '本日累计成交:', + ], + [ + 'tag' => 'a', + 'text' => "{$info['today_count']}", + ], + [ + 'tag' => 'text', + 'text' => $today_info ? '单。其中:' : '单', + ], + ]; + if($today_info){ + foreach ($today_info as $value) { + $temp_info = [ + [ + 'tag' => 'a', + 'text' => "{$value['brand_name']}", + ], + [ + 'tag' => 'text', + 'text' => '累计成交:', + ], + [ + 'tag' => 'a', + 'text' => "{$value['num']}", + ], + [ + 'tag' => 'text', + 'text' => '单', + ], + ]; + $content[] = $temp_info; + } + } + $content[] = [ + [ + 'tag' => 'text', + 'text' => '本月累计成交:', + ], + [ + 'tag' => 'a', + 'text' => "{$info['month_count']}", + ], + [ + 'tag' => 'text', + 'text' => $month_info ? '单。其中:' : '单', + ], + ]; + if($month_info){ + foreach ($month_info as $value) { + $temp_info = [ + [ + 'tag' => 'a', + 'text' => "{$value['brand_name']}", + ], + [ + 'tag' => 'text', + 'text' => '累计成交:', + ], + [ + 'tag' => 'a', + 'text' => "{$value['num']}", + ], + [ + 'tag' => 'text', + 'text' => '单', + ], + ]; + $content[] = $temp_info; + } + } + $content[] = [ + [ + 'tag' => 'text', + 'text' => '### 狸车加油,冲冲冲!💪🏻💪🏻💪🏻', + ], + ]; + $msg = [ + 'title' => $title, + 'content' => $content, + ]; + $data = [ + 'msg_type' => 'post', + 'content' => [ + 'post' => [ + "zh_cn" => $msg + ] + ], + ]; + return $data; + } }