123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- namespace app\admin\logic\live;
-
- use app\common\basics\Logic;
- use app\common\enum\LiveRoomEnum;
- use app\common\exception\WechatException;
- use app\common\model\live\LiveRoom;
- use app\common\model\shop\Shop;
- use app\common\server\UrlServer;
- use app\common\server\WxMnpLiveServer;
- use think\facade\Db;
-
-
- class LiveRoomLogic extends Logic
- {
-
-
-
- public static function listsQuery($params)
- {
- $where[] = ['del', '=', 0];
- if (!empty($params['shop_id'])) {
- $where[] = ['shop_id', '=', $params['shop_id']];
- }
- if (isset($params['status'])
- && $params['status'] != ''
- && in_array($params['status'], LiveRoomEnum::AUDIT_STATUS)) {
- $where[] = ['audit_status', '=', $params['status']];
- }
- if (!empty($params['live_info'])) {
- $where[] = ['name|anchor_name', 'like', '%' . $params['live_info'] . '%'];
- }
- if (!empty($params['live_status'])) {
- $where[] = ['live_status', '=', $params['live_status']];
- }
-
- if (isset($params['start_time']) && !empty($params['start_time'])) {
- $where[] = ['start_time', '>=', strtotime($params['start_time'])];
- }
- if (isset($params['end_time']) && !empty($params['end_time'])) {
- $where[] = ['end_time', '<=', strtotime($params['end_time'])];
- }
- return $where;
- }
-
-
-
-
- public static function lists($params)
- {
- $where = self::listsQuery($params);
-
- $count = LiveRoom::where($where)->count();
- $lists = LiveRoom::with(['shop'])->where($where)
- ->order(['id' => 'desc'])
- ->page($params['page'], $params['limit'])
- ->append(['live_time_text', 'live_status_text', 'audit_status_text'])
- ->select()->toArray();
-
- foreach ($lists as &$item) {
- $item['share_img'] = UrlServer::getFileUrl($item['share_img']);
- $item['feeds_img'] = UrlServer::getFileUrl($item['feeds_img']);
- $item['cover_img'] = UrlServer::getFileUrl($item['cover_img']);
- }
- return ['count' => $count, 'lists' => $lists];
- }
-
-
-
-
-
- public static function audit($params)
- {
- Db::startTrans();
- try {
- $room = LiveRoom::findOrEmpty($params['id']);
- if ($room['status'] > LiveRoomEnum::AUDIT_STATUS_WAIT) {
- throw new \Exception('该记录已审核');
- }
-
- if ($params['status'] == LiveRoomEnum::AUDIT_STATUS_FAIL && empty($params['audit_remark'])) {
- throw new \Exception('审核不通过请填写审核原因');
- }
-
- $update_data = [
- 'audit_remark' => $params['audit_remark'] ?? '',
- 'audit_status' => $params['status'],
- ];
-
-
- if ($params['status'] == LiveRoomEnum::AUDIT_STATUS_SUCCESS) {
- $room_id = self::createWxLiveRoom($room);
- $update_data['wx_room_id'] = $room_id;
- }
-
-
- LiveRoom::where(['id' => $params['id']])->update($update_data);
-
- Db::commit();
- return true;
- } catch (\Exception $e) {
- Db::rollback();
- self::$error = $e->getMessage();
- return false;
- }
- }
-
-
-
-
- public static function createWxLiveRoom($room)
- {
- $data = [
- 'name' => $room['name'],
- 'startTime' => $room['start_time'],
- 'endTime' => $room['end_time'],
- 'anchorName' => $room['anchor_name'],
- 'anchorWechat' => $room['anchor_wechat'],
- 'createrWechat' => $room['anchor_wechat'],
- 'shareImg' => $room['share_img_id'],
- 'feedsImg' => $room['feeds_img_id'],
- 'coverImg' => $room['cover_img_id'],
- 'type' => $room['type'],
- 'isFeedsPublic' => $room['is_feeds_public'],
- 'closeLike' => $room['close_like'],
- 'closeGoods' => $room['close_goods'],
- 'closeComment' => $room['close_comment'],
- 'closeReplay' => $room['close_replay'],
- 'closeShare' => $room['close_share'],
- 'closeKf' => $room['close_kf'],
- ];
- $result = (new WxMnpLiveServer())->handle('createLiveRoom', $data);
- return $result['roomId'];
- }
-
-
-
-
- public static function detail($id)
- {
- $detail = LiveRoom::where(['id' => $id])
- ->append(['audit_status_text'])
- ->findOrEmpty()->toArray();
- $detail['start_time'] = date('Y-m-d H:i:s', $detail['start_time']);
- $detail['end_time'] = date('Y-m-d H:i:s', $detail['end_time']);
- $detail['share_img'] = UrlServer::getFileUrl($detail['share_img']);
- $detail['feeds_img'] = UrlServer::getFileUrl($detail['feeds_img']);
- $detail['cover_img'] = UrlServer::getFileUrl($detail['cover_img']);
- return $detail;
- }
-
-
-
-
- public static function recommend($params)
- {
- return LiveRoom::update([
- 'id' => $params['id'],
- 'sort' => $params['sort'],
- ]);
- }
-
-
-
-
- public static function shopLists()
- {
- return Shop::field(['id', 'name'])
- ->where(['del' => 0])
- ->select()
- ->toArray();
- }
-
-
- }
|