<?php
/**
 * 公共Model
 * Created by PhpStorm.
 * User: 小威
 * Date: 2019/11/18
 * Time: 09:22
 */

namespace JinDouYun\Model\Common;

use Mall\Framework\Core\ErrorCode;
use Mall\Framework\Core\StatusCode;
use Mall\Framework\Core\ResultWrapper;

use JinDouYun\Model\SysAreaChina\MSysAreaChina;


class MCommon
{

    public function __construct()
    {

    }

    /**
     * 格式化source名称
     * @param $key
     * @return mixed
     */
    static function formatOrderSource($key)
    {
        $data = [
            StatusCode::$orderType['saleOrder'] => '销售订单',
            StatusCode::$orderType['purchaseOrder'] => '采购订单',
            StatusCode::$orderType['purchaseIn'] => '采购入库',
            StatusCode::$orderType['purchaseReturn'] => '采购退货',
            StatusCode::$orderType['saleOut'] => '销售出库',
            StatusCode::$orderType['saleReturn'] => '销售退货',
            StatusCode::$orderType['batch'] => '批次编号',
            StatusCode::$orderType['allocate'] => '调拨库存',
            StatusCode::$orderType['allocateOut'] => '调拨出库',
            StatusCode::$orderType['allocateIn'] => '调拨入库',
            StatusCode::$orderType['stocktaking'] => '盘点库存',
            StatusCode::$orderType['purchaseReturnOut'] => '采购退货出库',
            StatusCode::$orderType['saleReturnIn'] => '销售退货入库',
            StatusCode::$orderType['reportLoss'] => '库存报损',
            StatusCode::$orderType['merchantPurchase'] => '商户采购',
            StatusCode::$orderType['merchantPurchaseIn'] => '商户入库',
        ];
        if(!isset($data[$key])) return '';
        return $data[$key];
    }

    /**
     * 推
     */


    /**
     * 格式化地址信息
     * @param $data
     * @return
     */
    public function formatAddress($data)
    {
        $MSysAreaChina = new MSysAreaChina();
        foreach($data as $key => &$value){
            //处理地址
            if (isset($value['provinceCode']) && isset($value['cityCode']) && isset($value['districtCode'])) {
                $areaName = $MSysAreaChina->getNameByCode([
                    $value['provinceCode'],
                    $value['cityCode'],
                    $value['districtCode']
                ]);
                $value['area']['provinceName'] = isset($areaName[$value['provinceCode']]) ? $areaName[$value['provinceCode']] : '';
                $value['area']['cityName'] = isset($areaName[$value['cityCode']]) ? $areaName[$value['cityCode']] : '';
                $value['area']['districtName'] = isset($areaName[$value['districtCode']]) ? $areaName[$value['districtCode']] : '';
                $value['area']['address'] = $value['address'];
            }
        }
        return $data;
    }

}