132 lines
4.8 KiB
PHP
Executable File
132 lines
4.8 KiB
PHP
Executable File
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeshop开源商城系统
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||
// | github下载:https://github.com/likeshop-github
|
||
// | 访问官网:https://www.likeshop.cn
|
||
// | 访问社区:https://home.likeshop.cn
|
||
// | 访问手册:http://doc.likeshop.cn
|
||
// | 微信公众号:likeshop技术社区
|
||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||
// | likeshop团队版权所有并拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeshop.cn.team
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\api\lists;
|
||
|
||
|
||
use app\common\enum\OrderEnum;
|
||
use app\common\enum\YesNoEnum;
|
||
use app\common\lists\ListsExtendInterface;
|
||
use app\common\model\coach\Coach;
|
||
use app\common\model\goods\Goods;
|
||
use app\common\model\order\OrderGoods;
|
||
use app\common\service\FileService;
|
||
|
||
class CommentGoodsLists extends BaseApiDataLists implements ListsExtendInterface
|
||
{
|
||
/**
|
||
* @notes 搜索条件
|
||
* @return array
|
||
* @author ljj
|
||
* @date 2022/2/18 2:25 下午
|
||
*/
|
||
public function setSearch()
|
||
{
|
||
$where = [];
|
||
$where[] = ['o.user_id', '=', $this->userId];
|
||
$where[] = ['o.order_status', '=', OrderEnum::ORDER_STATUS_SERVER_FINISH];
|
||
$where[] = ['og.is_comment','=',$this->params['type'] ?? 0];
|
||
return $where;
|
||
}
|
||
|
||
/**
|
||
* @notes 评价商品列表
|
||
* @return array
|
||
* @author ljj
|
||
* @date 2022/2/21 5:59 下午
|
||
*/
|
||
public function lists(): array
|
||
{
|
||
$lists = OrderGoods::alias('og')
|
||
->join('order o', 'o.id = og.order_id')
|
||
->join('goods_comment gc','gc.order_goods_id = og.id')
|
||
->field('og.id,o.coach_id,og.goods_id,og.goods_name,og.goods_price,og.is_comment,appoint_time,og.goods_snap,gc.create_time')
|
||
->append(['goods_comment'])
|
||
->where($this->setSearch())
|
||
->limit($this->limitOffset, $this->limitLength)
|
||
->order('gc.id','desc')
|
||
->group('og.id')
|
||
->select()
|
||
->toArray();
|
||
$goodsIds = array_column($lists,'goods_id');
|
||
$coachIds = array_column($lists,'coach_id');
|
||
$goodsLists = Goods::where(['id'=>$goodsIds])->column('tags,order_num','id');
|
||
$coachLists = Coach::where(['id'=>$coachIds])->column('name,work_photo','id');
|
||
foreach ($lists as &$list) {
|
||
$list['goods_snap']['image'] = FileService::getFileUrl($list['goods_snap']['image']);
|
||
$list['goods_snap']['tags'] = $goodsLists[$list['goods_id']]['tags'] ?? 0;
|
||
$list['goods_snap']['order_num'] = $goodsLists[$list['goods_id']]['order_num'] ?? 0;
|
||
$list['appoint_date'] = date('m-d',$list['appoint_time']);
|
||
$list['appoint_time'] = date('H:i',$list['appoint_time']);
|
||
$list['coach_info'] = $coachLists[$list['coach_id']] ?? [];
|
||
$list['coach_info']['work_photo'] = FileService::getFileUrl($list['coach_info']['work_photo'] ?? '');
|
||
}
|
||
|
||
return $lists;
|
||
}
|
||
|
||
/**
|
||
* @notes 评价商品总数
|
||
* @return int
|
||
* @author ljj
|
||
* @date 2022/2/21 5:59 下午
|
||
*/
|
||
public function count(): int
|
||
{
|
||
return OrderGoods::alias('og')
|
||
->join('order o', 'o.id = og.order_id')
|
||
->where($this->setSearch())
|
||
->group('og.id')
|
||
->count();
|
||
}
|
||
|
||
/**
|
||
* @notes 评价商品数据统计
|
||
* @return array
|
||
* @author ljj
|
||
* @date 2022/2/21 6:00 下午
|
||
*/
|
||
public function extend()
|
||
{
|
||
$waitWhere = [
|
||
['o.user_id', '=', $this->userId],
|
||
['o.order_status', '=', 3],
|
||
['og.is_comment', '=', YesNoEnum::NO],
|
||
];
|
||
$wait = OrderGoods::alias('og')
|
||
->leftJoin('order o', 'o.id = og.order_id')
|
||
->where($waitWhere)
|
||
->count();
|
||
$finishWhere = [
|
||
['o.user_id', '=', $this->userId],
|
||
['o.order_status', '=', 3],
|
||
['og.is_comment', '=', YesNoEnum::YES],
|
||
];
|
||
$finish = OrderGoods::alias('og')
|
||
->leftJoin('order o', 'o.id = og.order_id')
|
||
->Join('goods_comment go', 'og.id = go.order_goods_id')
|
||
->where($finishWhere)
|
||
->whereNull('go.delete_time')
|
||
->count();
|
||
return [
|
||
'wait' => $wait,
|
||
'finish' => $finish
|
||
];
|
||
}
|
||
} |