StoreServiceLog.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/12/23
  6. */
  7. namespace app\models\store;
  8. use app\models\user\User;
  9. use crmeb\basic\BaseModel;
  10. use crmeb\traits\ModelTrait;
  11. /**
  12. * TODO 客服信息Model
  13. * Class StoreServiceLog
  14. * @package app\models\store
  15. */
  16. class StoreServiceLog extends BaseModel
  17. {
  18. /**
  19. * 数据表主键
  20. * @var string
  21. */
  22. protected $pk = 'id';
  23. /**
  24. * 模型名称
  25. * @var string
  26. */
  27. protected $name = 'store_service_log';
  28. /**
  29. * 消息类型
  30. * @var array 1=文字 2=表情 3=图片 4=语音 5 = 商品链接 6 = 订单类型
  31. */
  32. const MSN_TYPE = [1, 2, 3, 4, 5, 6];
  33. /**
  34. * 商品链接消息类型
  35. */
  36. const MSN_TYPE_GOODS = 5;
  37. /**
  38. * 订单信息消息类型
  39. */
  40. const MSN_TYPE_ORDER = 6;
  41. use ModelTrait;
  42. /**
  43. * 客服聊天记录
  44. * @param $uid
  45. * @param $toUid
  46. * @param $page
  47. * @param $limit
  48. * @return array
  49. */
  50. public static function lst($uid, $toUid, $page, $limit)
  51. {
  52. if (!$limit || !$page) return [];
  53. $model = new self;
  54. $model = $model->whereIn('uid', [$uid, $toUid]);
  55. $model = $model->whereIn('to_uid', [$uid, $toUid]);
  56. $model = $model->order('id DESC');
  57. $model = $model->page($page, $limit);
  58. return $model->select()->each(function ($item) {
  59. $userInfo = User::getUserInfo($item['uid'], 'nickname,avatar');
  60. $item['nickname'] = $userInfo['nickname'];
  61. $item['avatar'] = $userInfo['avatar'];
  62. if ($item['msn_type'] == self::MSN_TYPE_GOODS && $item['msn']) {
  63. $item['productInfo'] = StoreProduct::validWhere()->where('id', $item['msn'])->find();
  64. } else {
  65. $item['productInfo'] = [];
  66. }
  67. $item['orderInfo'] = [];
  68. if ($item['msn_type'] == self::MSN_TYPE_ORDER && $item['msn']) {
  69. $order = StoreOrder::getUserOrderDetail($item['uid'], $item['msn']);
  70. if ($order) {
  71. $order = StoreOrder::tidyOrder($order->toArray(), true, true);
  72. $order['add_time_y'] = date('Y-m-d', $order['add_time']);
  73. $order['add_time_h'] = date('H:i:s', $order['add_time']);
  74. $item['orderInfo'] = $order;
  75. }
  76. }
  77. });
  78. }
  79. }