You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/application/merchant/model/wechat/StoreService.php

82 lines
3.2 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\merchant\model\wechat;
use app\merchant\model\wechat\StoreServiceLog as ServiceLogModel;
use app\admin\model\wechat\WechatUser;
use app\merchant\model\user\User;
use app\merchant\model\merchant\Merchant;
use traits\ModelTrait;
use basic\ModelBasic;
/**
* 客服管理 model
* Class StoreService
* @package app\merchant\model\wechat
*/
class StoreService extends ModelBasic
{
use ModelTrait;
public static function setWhere($where)
{
$model = new self();
if (isset($where['mer_id']) && $where['mer_id']) {
$model = $model->where('mer_id', $where['mer_id']);
}
if (isset($where['status']) && $where['status']) {
$model = $model->where('status', $where['status']);
}
if (isset($where['title']) && $where['title']) {
$model = $model->where('nickname', 'like', "%$where[title]%");
}
return $model;
}
/**
* @return array
*/
public static function getList($where)
{
$data = self::setWhere($where)->page($where['page'], $where['limit'])->order('sort desc,id desc')->select();
$data = count($data) > 0 ? $data->toArray() : [];
$count = self::setWhere($where['mer_id'])->count();
return compact('data', 'count');
}
/**
* @return array
*/
public static function getChatUser($uid, $mer_id, $page, $limit)
{
$list = [];
$count = 0;
$where = 'mer_id = ' . $mer_id . ' AND (uid = ' . $uid . ' OR to_uid=' . $uid . ')';
$chat_list = ServiceLogModel::field("uid,to_uid")->page($page,$limit)->where($where)->group("uid,to_uid")->select();
if (!count($chat_list)) return compact('list', 'count');
$arr_user = $arr_to_user = [];
foreach ($chat_list as $key => $value) {
array_push($arr_user, $value["uid"]);
array_push($arr_to_user, $value["to_uid"]);
}
$uids = array_merge($arr_user, $arr_to_user);
$data = User::field("uid,nickname,avatar")->where(array("uid" => array(array("in", $uids), array("neq", $uid))))->select();
$data = count($data) > 0 ? $data->toArray() : [];
foreach ($data as $index => $user) {
$service = self::field("uid,nickname,avatar")->where(array("uid" => $user["uid"]))->find();
if ($service) $data[$index] = $service;
}
$count = User::where(array("uid" => array(array("in", $uids), array("neq", $uid))))->count();
return compact('data', 'count');
}
}