Açıklama Yok

MonitorEmptyFreightCost.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php namespace App\Console\Commands;
  2. use Illuminate\Console\Command;
  3. use Illuminate\Support\Facades\DB;
  4. define("YP_SMS_KEY_1", "fbdb5f2ddae13c2f4a592348bfe52137");
  5. class MonitorEmptyFreightCost extends Command {
  6. protected $name = 'MonitorEmptyFreightCost';
  7. protected $description = '监控分销商C仓已发货订单运费是否需要手动处理';
  8. protected $templateId = '3750860';
  9. protected $phoneArr = ['13161864516'];
  10. protected $dr_name = '清平乐';
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function handle()
  16. {
  17. $this->MonitorEmptyFreightCost();
  18. }
  19. public function MonitorEmptyFreightCost()
  20. {
  21. //查询2天前C仓已发货但订单运费为0的订单
  22. $endTime = date('Y-m-d', strtotime('-2 days'));
  23. $orderIdList = DB::table('order')->where('send_time','<',$endTime)->where('warehouse',3)->where('is_del',0)
  24. ->where('logistics_id','>','')->where('status',3)->whereNull('freight_cost')->lists('id');
  25. if(count($orderIdList) > 0) {
  26. foreach($this->phoneArr as $phone) {
  27. $this->sendMsg($phone, [$this->dr_name=>$orderIdList]);
  28. }
  29. }
  30. echo 'SUCCESS';
  31. }
  32. public function sendMsg($phone, $orders)
  33. {
  34. $orders = json_encode($orders,JSON_UNESCAPED_UNICODE);//防止中文被转义
  35. $params = ('#order#').'='.$orders;
  36. //提醒销售
  37. self::sendMsgWithParams($phone,$params, $this->templateId);
  38. }
  39. private static function init(){
  40. $ch = curl_init();
  41. /* 设置验证方式 */
  42. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
  43. 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
  44. /* 设置返回结果为流 */
  45. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  46. /* 设置超时时间*/
  47. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  48. /* 设置通信方式 */
  49. curl_setopt($ch, CURLOPT_POST, 1);
  50. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  51. return $ch;
  52. }
  53. private static function checkErr($result,$error) {
  54. if($result === false)
  55. {
  56. echo 'Curl error: ' . $error;
  57. }
  58. // else
  59. // {
  60. // echo '操作完成没有任何错误';
  61. // }
  62. }
  63. private static function send($ch,$data){
  64. curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
  65. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  66. $result = curl_exec($ch);
  67. $error = curl_error($ch);
  68. self::checkErr($result,$error);
  69. return $result;
  70. }
  71. //有参数发送短信验证码
  72. public static function sendMsgWithParams($phone, $params, $template_id) {
  73. $ch=self::init();
  74. $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone,'tpl_value'=>$params);
  75. $json_data = self::send($ch,$data);
  76. $array = json_decode($json_data,true);
  77. curl_close($ch);
  78. // $json_data = iconv('utf-8','gbk',$json_data);
  79. // print_r($json_data);
  80. return $array;
  81. }
  82. //无参数发送短信验证码
  83. public static function sendMsgSimple($phone, $template_id) {
  84. $ch=self::init();
  85. $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone);
  86. $json_data = self::send($ch,$data);
  87. $array = json_decode($json_data,true);
  88. curl_close($ch);
  89. return $array;
  90. }
  91. }