64], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'cx_mch_id' => '平台商户ID', 'type' => '类型,0=阿里云,1=腾讯云', 'key' => 'KEY', 'tpl_code' => '短信模板', 'is_delete' => '是否删除,0=否,1=是', 'created_at' => '添加时间', ]; } public function beforeSave($insert) { if(parent::beforeSave($insert)){ if($this->isNewRecord){ $this->created_at = time(); } $this->htmlTagFilter(); return true; } else { return false; } } public function htmlTagFilter() { $this->key = Model::htmlTagFilter($this->key); $this->tpl_code = Model::htmlTagFilter($this->tpl_code); } public static function getTplList($type = SmsSetting::TYPE_ALIYUN, $cx_mch_id = 0) { $list = [ [ 'key' => self::TYPE_ORDER_GOODS_CLOSE, 'label' => '商品订单支付提醒', 'tpl_code' => '', 'tip' => '您在冠亿城小程序中有一笔待支付订单:${order_no},如您已支付请忽略', ], [ 'key' => self::TYPE_STORE_DZ_YES, 'label' => '同意成为店长', 'tpl_code' => '', 'tip' => '您预约门店[${store}]店长,已预约成功,地址:${location},时间:${date1}-${date2},门店联系电话:${phone}', ], [ 'key' => self::TYPE_STORE_DZ_NO, 'label' => '拒绝成为店长', 'tpl_code' => '', 'tip' => '您预约提交的${store}门店 ${date},预约已审核,${msg}', ], [ 'key' => self::TYPE_STORE_BJ, 'label' => '通知保洁', 'tpl_code' => '', 'tip' => '打扫门店:${store},包厢:${name},门店地址:${location},门店联系电话:${phone}', ], ]; foreach ($list as $index => $item){ $item['tpl_code'] = self::getTpl($item['key'], $type, $cx_mch_id); $list[$index] = $item; } return $list; } public static function getTpl($key, $type = SmsSetting::TYPE_ALIYUN, $cx_mch_id = 0) { $cache_key = "{$key}_{$type}_{$cx_mch_id}"; $cache_val = FlashStorage::getCache($cache_key); $cache_val = YII_ENV_PROD ? $cache_val : false; if($cache_val === false){ $model = SmsTpl::findOne([ 'cx_mch_id' => $cx_mch_id, 'type' => $type, 'key' => $key, 'is_delete' => 0 ]); $cache_val = $model != null ? $model->tpl_code : null; if($cache_val != null){ FlashStorage::setCache($cache_key, $cache_val); } } return $cache_val; } public static function tplKeyLables() { return [ '0' => self::TYPE_ORDER_GOODS_CLOSE, '1' => self::TYPE_STORE_DZ_YES, '2' => self::TYPE_STORE_DZ_NO, '3' => self::TYPE_STORE_BJ, ]; } public static function getTplKey($type) { $lables = self::tplKeyLables(); return isset($lables[$type]) ? $lables[$type] : self::TYPE_VALIDATE_IDENTIFY; } public static function typeLabels() { $cache_key = "_s_t_t_"; $cache_val = FlashStorage::getCache($cache_key); if($cache_val !== false) return $cache_val; $tpl_list = self::getTplList(); $tpl_key_labels = self::tplKeyLables(); $list = []; foreach ($tpl_key_labels as $key => $val){ foreach ($tpl_list as $index => $item){ if($item['key'] == $val){ $list[] = [ 'type' => $key, 'label' => $item['label'] ]; break; } } } FlashStorage::setCache($cache_key, $list,86400); return $list; } }