123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- define("YP_SMS_KEY_1", "fbdb5f2ddae13c2f4a592348bfe52137");
- class MonitorEmptyFreightCost extends Command {
- protected $name = 'MonitorEmptyFreightCost';
- protected $description = '监控分销商C仓已发货订单运费是否需要手动处理';
- protected $templateId = '3750860';
- protected $phoneArr = ['13161864516'];
- protected $dr_name = '清平乐';
- public function __construct()
- {
- parent::__construct();
- }
- public function handle()
- {
- $this->MonitorEmptyFreightCost();
- }
- public function MonitorEmptyFreightCost()
- {
- //查询2天前C仓已发货但订单运费为0的订单
- $endTime = date('Y-m-d', strtotime('-2 days'));
- $orderIdList = DB::table('order')->where('send_time','<',$endTime)->where('warehouse',3)->where('is_del',0)
- ->where('logistics_id','>','')->where('status',3)->whereNull('freight_cost')->lists('id');
- if(count($orderIdList) > 0) {
- foreach($this->phoneArr as $phone) {
- $this->sendMsg($phone, [$this->dr_name=>$orderIdList]);
- }
- }
- echo 'SUCCESS';
- }
- public function sendMsg($phone, $orders)
- {
- $orders = json_encode($orders,JSON_UNESCAPED_UNICODE);//防止中文被转义
- $params = ('#order#').'='.$orders;
- //提醒销售
- self::sendMsgWithParams($phone,$params, $this->templateId);
- }
- private static function init(){
- $ch = curl_init();
- /* 设置验证方式 */
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
- 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
- /* 设置返回结果为流 */
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- /* 设置超时时间*/
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- /* 设置通信方式 */
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- return $ch;
- }
- private static function checkErr($result,$error) {
- if($result === false)
- {
- echo 'Curl error: ' . $error;
- }
- // else
- // {
- // echo '操作完成没有任何错误';
- // }
- }
- private static function send($ch,$data){
- curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
- $result = curl_exec($ch);
- $error = curl_error($ch);
- self::checkErr($result,$error);
- return $result;
- }
- //有参数发送短信验证码
- public static function sendMsgWithParams($phone, $params, $template_id) {
- $ch=self::init();
- $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone,'tpl_value'=>$params);
- $json_data = self::send($ch,$data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- // $json_data = iconv('utf-8','gbk',$json_data);
- // print_r($json_data);
- return $array;
- }
- //无参数发送短信验证码
- public static function sendMsgSimple($phone, $template_id) {
- $ch=self::init();
- $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone);
- $json_data = self::send($ch,$data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- return $array;
- }
- }
|