StoreServiceLog.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 = StoreService::where('uid', $item['uid'])->field('nickname,avatar')->find();
  60. if(!$userInfo) $userInfo = User::getUserInfo($item['uid'],'nickname,avatar');
  61. if ($userInfo) {
  62. $item['nickname'] = $userInfo['nickname'];
  63. $item['avatar'] = $userInfo['avatar'];
  64. }
  65. if ($item['msn_type'] == self::MSN_TYPE_GOODS && $item['msn']) {
  66. $item['productInfo'] = StoreProduct::validWhere()->where('id', $item['msn'])->find();
  67. } else {
  68. $item['productInfo'] = [];
  69. }
  70. $item['orderInfo'] = [];
  71. if ($item['msn_type'] == self::MSN_TYPE_ORDER && $item['msn']) {
  72. $order = StoreOrder::getUserOrderDetail($item['uid'], $item['msn']);
  73. if ($order) {
  74. $order = StoreOrder::tidyOrder($order->toArray(), true, true);
  75. $order['add_time_y'] = date('Y-m-d', $order['add_time']);
  76. $order['add_time_h'] = date('H:i:s', $order['add_time']);
  77. $item['orderInfo'] = $order;
  78. }
  79. }
  80. $item['msn_type'] = (int)$item['msn_type'];
  81. });
  82. }
  83. }