Commit e559911c1d298227a9f36755db4d653e262f471f
1 parent
e64fc187
Exists in
master
app-wx(v0.1.0 build 24)
1. F截取短信模板发送变量的长度
Showing
4 changed files
with
31 additions
and
14 deletions
Show diff stats
app-wx/config/params.php
app-wx/controllers/SiteController.php
... | ... | @@ -2,9 +2,6 @@ |
2 | 2 | namespace app\wx\controllers; |
3 | 3 | |
4 | 4 | use Yii; |
5 | -use app\wx\models\Engineer; | |
6 | -use common\models\EngineerProfile; | |
7 | -use common\helpers\WxHelper; | |
8 | 5 | use common\models\SysSetting; |
9 | 6 | |
10 | 7 | use stdClass; |
... | ... | @@ -42,8 +39,6 @@ class SiteController extends BaseController |
42 | 39 | /** |
43 | 40 | * 构造user的共用信息 |
44 | 41 | */ |
45 | - | |
46 | - | |
47 | 42 | return $this->render('index'); |
48 | 43 | } |
49 | 44 | ... | ... |
app-wx/modules/order/controllers/DefaultController.php
... | ... | @@ -7,6 +7,7 @@ use yii\helpers\HtmlPurifier; |
7 | 7 | use yii\base\Exception; |
8 | 8 | use yii\log\Logger; |
9 | 9 | |
10 | +use common\helpers\Utils; | |
10 | 11 | use common\helpers\ImageManager; |
11 | 12 | use domain\order\RepairOrder; |
12 | 13 | use domain\order\RepairOrderImages; |
... | ... | @@ -132,11 +133,11 @@ class DefaultController extends BaseController |
132 | 133 | 您好,维修厂${maintainer}已进行维修,预计完成时间${dateTime},预估维修内容${repairPlan},预估维修费用${repairPrice},维修厂地址:${address},联系电话:${tel} |
133 | 134 | * */ |
134 | 135 | $smsVars = ['maintainer' => '', 'tel' => '', 'address' => '', 'dateTime' => '', 'repairPlan' => '', 'repairPrice' => '']; |
135 | - $smsVars['maintainer'] = $orderModel->maintainer_name; | |
136 | + $smsVars['maintainer'] = Utils::cutStrTxt($orderModel->maintainer_name); | |
136 | 137 | $smsVars['tel'] = $orderModel->maintainer_tel; |
137 | - $smsVars['address'] = $orderModel->maintainer_address; | |
138 | + $smsVars['address'] = Utils::cutStrTxt($orderModel->maintainer_address); | |
138 | 139 | $smsVars['dateTime'] = date('Y年m月d日 H点', $orderModel->predict_finish_time); |
139 | - $smsVars['repairPlan'] = $orderModel->predict_fault; | |
140 | + $smsVars['repairPlan'] = Utils::cutStrTxt($orderModel->predict_fault); | |
140 | 141 | $smsVars['repairPrice'] = $orderModel->predict_price; |
141 | 142 | $phone = $orderModel->contact_mobile; |
142 | 143 | $sms = new SmsMessage(); |
... | ... | @@ -155,7 +156,7 @@ class DefaultController extends BaseController |
155 | 156 | $smsVars = ['maintainer' => '', 'code' => '', 'tel' => '']; |
156 | 157 | |
157 | 158 | $smsVars['tel'] = Yii::$app->params['SERVICE_PHONE']; |
158 | - $smsVars['maintainer'] = $orderModel->maintainer_name; | |
159 | + $smsVars['maintainer'] = Utils::cutStrTxt($orderModel->maintainer_name); | |
159 | 160 | $smsVars['code'] = $orderModel->short_uuid." "; //防止后面的文字和这个参数粘贴在一起 |
160 | 161 | $phone = $orderModel->contact_mobile; |
161 | 162 | $sms = new SmsMessage(); |
... | ... | @@ -166,10 +167,14 @@ class DefaultController extends BaseController |
166 | 167 | public function actionSms() |
167 | 168 | { |
168 | 169 | $userId = $this->getUserId(); |
169 | - $orderModel = RepairOrderRepository::findOne(['id' => 12]); | |
170 | - //$result = $this->sendSubmitSMS($orderModel, $userId); | |
171 | - //var_dump($result); | |
172 | - //$this->sendFinishSMS($orderModel, $userId); | |
170 | + $orderModel = RepairOrderRepository::findOne(['id' => 18]); | |
171 | + //$result1 = $this->sendSubmitSMS($orderModel, $userId); | |
172 | + | |
173 | + //$result2 = $this->sendFinishSMS($orderModel, $userId); | |
174 | + | |
175 | + //var_dump($result1); | |
176 | + //var_dump($result2); | |
177 | + | |
173 | 178 | } |
174 | 179 | |
175 | 180 | /** | ... | ... |
common/helpers/Utils.php
... | ... | @@ -434,6 +434,23 @@ class Utils |
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
437 | + * 裁剪字符串长度 | |
438 | + * @param $str | |
439 | + * @return string | |
440 | + */ | |
441 | + public static function cutStrTxt($str, $maxLen = 20) | |
442 | + { | |
443 | + $strLen = mb_strlen($str); | |
444 | + if ($strLen <= $maxLen && $strLen > 0) { | |
445 | + return $str; | |
446 | + } elseif($strLen > $maxLen) { | |
447 | + return mb_substr($str, 0, $maxLen-2).'……'; | |
448 | + } else { | |
449 | + return ''; | |
450 | + } | |
451 | + } | |
452 | + | |
453 | + /** | |
437 | 454 | * 获取秒数对应的天/时/分 |
438 | 455 | * @param $time |
439 | 456 | * @return string | ... | ... |