StoreServiceLog.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\models\wechat;
  3. use app\models\user\User;
  4. use crmeb\traits\ModelTrait;
  5. use crmeb\basic\BaseModel;
  6. /**
  7. * 客服管理 model
  8. * Class StoreProduct
  9. * @package app\models\store
  10. */
  11. class StoreServiceLog extends BaseModel
  12. {
  13. /**
  14. * 数据表主键
  15. * @var string
  16. */
  17. protected $pk = 'id';
  18. /**
  19. * 模型名称
  20. * @var string
  21. */
  22. protected $name = 'store_service_log';
  23. use ModelTrait;
  24. protected function getAddTimeAttr($value)
  25. {
  26. return $value ? date('Y-m-d H:i:s', $value) : '';
  27. }
  28. /**
  29. * @param $where
  30. * @return array
  31. */
  32. public static function getChatList($where, $mer_id)
  33. {
  34. $model = new self;
  35. $model = $model->where('mer_id', $mer_id);
  36. $model = $model->whereIn('uid', [$where['uid'], $where['to_uid']]);
  37. $model = $model->whereIn('to_uid', [$where['uid'], $where['to_uid']]);
  38. $count = $model->count();
  39. $model->order("add_time desc");
  40. $list = $model->select()
  41. ->each(function ($item) use ($mer_id) {
  42. $user = StoreService::field("nickname,avatar")->where('mer_id', $mer_id)->where(array("uid" => $item["uid"]))->find();
  43. if (!$user) $user = User::field("nickname,avatar")->where(array("uid" => $item["uid"]))->find();
  44. $item["nickname"] = $user["nickname"];
  45. $item["avatar"] = $user["avatar"];
  46. });
  47. return compact('count', 'list');
  48. }
  49. }