| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.com
- * =========================================================
- */
- namespace addon\wechat\model;
- use app\model\BaseModel;
- /**
- * 微信回复
- */
- class Replay extends BaseModel
- {
- /*******************************************************************************微信回复开始*****************************************************/
- /**
- * 添加微信关键词回复
- * @param array $data
- */
- public function addRule($data)
- {
- $res = model('wechat_replay_rule')->add($data);
- if ($res === false) {
- return $this->error($res, 'SAVE_FAIL');
- }
- return $this->success($res, 'SAVE_SUCCESS');
- }
- /**
- * 修改微信关键词回复
- * @param array $data
- * @param array $condition
- * @return multitype:string mixed
- */
- public function editRule($data, $condition)
- {
- $res = model('wechat_replay_rule')->update($data, $condition);
- if ($res === false) {
- return $this->error($res, 'SAVE_FAIL');
- }
- return $this->success($res, 'SAVE_SUCCESS');
- }
- /**
- * 删除微信关键词回复
- * @param array $condition
- * @return multitype:string mixed
- */
- public function deleteRule($condition)
- {
- $res = model('wechat_replay_rule')->delete($condition);
- if ($res === false) {
- return $this->error($res, 'DELETE_FAIL');
- }
- return $this->success($res, 'DELETE_SUCCESS');
- }
- /**
- * 获取微信关键词回复信息
- * @param array $condition
- * @param string $field
- * @return multitype:string mixed
- */
- public function getRuleInfo($condition, $field = '*')
- {
- $info = model('wechat_replay_rule')->getInfo($condition, $field);
- return $this->success($info);
- }
- /**
- * 获取回复列表
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- * @return multitype:string mixed
- */
- public function getReplayPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('wechat_replay_rule')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
- /**
- * 获取站点关键字回复
- * @param unknown $site_id
- * @param unknown $keyWords
- */
- public function getSiteWechatKeywordsReplay($keywords, $site_id)
- {
- $list = model('wechat_replay_rule')->getList([['rule_type', '=', 'KEYWORDS'], ['site_id', '=', $site_id]]);
- $default_list = model('wechat_replay_rule')->getList([['rule_type', '=', 'DEFAULT'], ['site_id', '=', $site_id]]);
- $rule_list = array();
- $text = '';
- foreach ($list as $k => $v) {
- $kewords_array = json_decode($v['keywords_json'], true);
- $replay_array = json_decode($v['replay_json'], true);
- if (!empty($kewords_array) && !empty($replay_array)) {
- foreach ($kewords_array as $k_key => $v_key) {
- $text = $v_key['keywords_name'] . ',' . $text;
- if (($v_key['keywords_type'] == 0 && $v_key['keywords_name'] == $keywords) || ($v_key['keywords_type'] == 1 && (strpos($keywords, $v_key['keywords_name']) !== false))) {
- $num = rand(0, count($replay_array) - 1);
- $rule_list[] = $replay_array[$num];
- }
- }
- }
- }
- if (empty($rule_list)) {
- $default_rule_list = array();
- foreach ($default_list as $kk => $vv) {
- $default_replay_array = json_decode($vv['replay_json'], true);
- if (!empty($default_replay_array)) {
- $num = rand(0, count($replay_array) - 1);
- $default_rule_list[] = $default_replay_array[$num];
- }
- }
- if (!empty($default_rule_list)){
- $rule = $default_rule_list[0];
- }else{
- $rule = [];
- }
- } else {
- $rule = $rule_list[0];
- }
- return $this->success($rule);
- }
- /**
- * 获取微信关注回复
- * @param unknown $from_user
- * @param unknown $to_user
- * @param unknown $site_id
- * @param unknown $keywords
- */
- function getWechatFollowReplay($site_id)
- {
- $follow_info = model('wechat_replay_rule')->getInfo([['rule_type', '=', 'AFTER'], ['site_id', '=', $site_id]]);
- $replay_content = '';
- if (!empty($follow_info['replay_json'])) {
- $replay_info = json_decode($follow_info['replay_json'], true);
- switch ($replay_info[0]['type']) {
- case 'text' :
- $replay_content = $replay_info[0]['reply_content'];
- break;
- case 'articles' :
- $replay_content = '';
- break;
- }
- }
- return $this->success($replay_content);
- }
- /*******************************************************************************微信回复结束*****************************************************/
- }
|