105 lines
3.8 KiB
PHP
105 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace app\api\lists\order;
|
|
|
|
|
|
use app\admin\lists\BaseAdminDataLists;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\model\store_order\StoreOrder;
|
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
|
use app\common\model\store_product\StoreProduct;
|
|
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
|
use app\common\model\store_product_unit\StoreProductUnit;
|
|
use Picqer\Barcode\BarcodeGeneratorPNG;
|
|
|
|
/**
|
|
* 零售订单列表
|
|
* Class RetailOrderList
|
|
* @package app\api\order
|
|
*/
|
|
class OrderList extends BaseAdminDataLists implements ListsSearchInterface
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 设置搜索条件
|
|
* @return \string[][]
|
|
* @author likeadmin
|
|
*/
|
|
public function setSearch(): array
|
|
{
|
|
return [
|
|
'=' => ['paid', 'status', 'is_writeoff','reservation'],
|
|
'between_time' => 'create_time',
|
|
'%like%' => ['order_id'],
|
|
];
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 零售订单列表
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @date 2024/04/27 11:26
|
|
*/
|
|
public function lists(): array
|
|
{
|
|
$userId = $this->request->userId;
|
|
if (!$userId) return [];
|
|
$data = StoreOrder::with(['store'])->where($this->searchWhere)->where(['uid'=>$userId])
|
|
->whereIn('shipping_type',[1,2])
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->order(['id' => 'desc'])
|
|
->select()
|
|
->each(function ($item) {
|
|
$item['goods_list'] = StoreOrderCartInfo::where('oid', $item['id'])
|
|
->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time,attr_value_id,price')->limit(3)->select()
|
|
->each(function ($v){
|
|
$find=StoreProduct::where('id', $v['product_id'])->field('store_name,image')->find();
|
|
$attr_value=StoreProductAttrValue::where('id',$v['attr_value_id'])->find();
|
|
$name='';
|
|
if($attr_value){
|
|
$name=StoreProductUnit::where('id',$attr_value['unit'])->value('name');
|
|
}
|
|
$v['store_name'] = $find['store_name'] ?? '';
|
|
$v['sku_name'] = $attr_value['sku_name'] ?? '';
|
|
$v['image'] = $find['image'] ?? '';
|
|
$v['price'] = $v['price']??'';
|
|
$v['unit_name']=$name;
|
|
});
|
|
$item['goods_count'] = count(explode(',', $item['cart_id']));
|
|
if ($item['refund_reason_time']) {
|
|
$item['refund_reason_time'] = date('Y-m-d H:i:s', $item['refund_reason_time']);
|
|
}
|
|
if ($item['pay_time']) {
|
|
$item['pay_time'] = date('Y-m-d H:i:s', $item['pay_time']);
|
|
}
|
|
if($item['verify_img']){
|
|
$item['verify_img'] = 'https://'.$this->request->host(true).$item['verify_img'];
|
|
}
|
|
if($item['is_writeoff']==0){
|
|
$generator = new BarcodeGeneratorPNG();
|
|
$tmpFilename = $generator->getBarcode($item['verify_code'], $generator::TYPE_CODE_128);
|
|
$item['verify_base64'] ='data:image/png;base64,'.base64_encode($tmpFilename);
|
|
}
|
|
})
|
|
->toArray();
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 零售订单数量
|
|
* @return int
|
|
* @date 2024/04/27 11:26
|
|
*/
|
|
public function count(): int
|
|
{
|
|
$userId = $this->request->userId;
|
|
return StoreOrder::where($this->searchWhere)->whereIn('shipping_type',[1,2])->where('uid', $userId)->count();
|
|
}
|
|
}
|