<?php

namespace app\admin\controller\company;

use app\admin\controller\AuthController;
use app\admin\model\order\StoreOrder as StoreOrderModel;
use app\models\system\SystemStore;
use app\admin\model\store\{
    StoreDescription,
    StoreProductAttrValue,
    StoreProductAttr,
    StoreProductAttrResult,
    StoreProductCate,
    StoreProductRelation,
    StoreCategory as CategoryModel,
    StoreProduct as ProductModel
};
use app\admin\model\ump\StoreBargain;
use app\admin\model\ump\StoreCombination;
use app\admin\model\ump\StoreSeckill;
use crmeb\services\{JsonService, JsonService as Json, UtilService as Util, FormBuilder as Form};
use crmeb\traits\CurdControllerTrait;
use think\facade\Route as Url;
use app\admin\model\system\{
    SystemAttachment, ShippingTemplates
};


/**
 * 产品管理
 * Class StoreProduct
 * @package app\admin\controller\store
 */
class Order extends AuthController
{

    use CurdControllerTrait;

    protected $bindModel = ProductModel::class;

    /**
     * @return mixed
     */
    public function index()
    {
        $this->assign([
            'year' => get_month(),
            'real_name' => $this->request->get('real_name', ''),
            'status' => $this->request->param('status', ''),
            'orderCount' => StoreOrderModel::orderCount($this->adminInfo['store_id']),
            'payTypeCount' => StoreOrderModel::payTypeCount($this->adminInfo['store_id']),
        ]);
        $this->assign('type', $this->adminInfo['type']);
        if ($this->adminInfo['type'] == 0) {
            $this->assign('store', SystemStore::where('is_show', 1)->where('is_del', 0)->field('id,name')->select());
        }
        $this->assign('store_id', $this->adminInfo['store_id']);
        return $this->fetch();
    }

    /**
     * 获取头部订单金额等信息
     * return json
     */
    public function getBadge()
    {
        $where = Util::postMore([
            ['status', ''],
            ['real_name', ''],
            ['is_del', 0],
            ['data', ''],
            ['type', ''],
            ['pay_type', ''],
            ['order', ''],
        ]);
        $where['store_id'] = $this->adminInfo['store_id'];
        if ($this->request->post('store_id') > 0) $where['store_id'] = $this->request->post('store_id');
        return Json::successful(StoreOrderModel::getBadge($where));
    }
}
