<?php
/**
  * @method 定时任务
  * @author soul 2017/6/16
  */
class autoAction
{
	/**
	  * @method 同步用户表
	  * @author soul 2017/6/22
	  */
	function all()
	{
		$this->updateUser();
		$this->autoCloseOrder();
		$this->autoPayOrder();
		$this->autoOrderRefundStatus();
		$this->autoOkOrder();
		$this->autoTiXian();
	}

	/**
	  * @method 同步用户表
	  * @author soul 2017/6/22
	  */
	function updateUser()
	{
		$B2cUser = new B2cUser();
		$B2cUser->updateUserByApi();
		echo 'ok';
	}

	
	/**
	  * @method 更新词典
	  * @author soul 2017/6/16
	  */
	function updateDist()
	{
		$OthDist = new OthDist();
		$OthDist->update();
		echo 'ok';
	}
	
	
	
	/**
	  * @method 重置关键字
	  * @author soul 2017/6/16
	  */
	function keyword()
	{
		$this->updateDist();
		$B2cBase = new B2cBase();
		$res = $B2cBase->getFieldUniVal('bc_product', 'pro_id');
		$B2cKeyword = new B2cKeyword();
		$B2cKeyword->resetProductKeyword($res['data']);
		$res = $B2cBase->getFieldUniVal('sh_shop', 'shop_id');
		$B2cKeyword->resetShopKeyword($res['data']);
		echo 'ok';
	}

	/**
	  * @method 初始化新店铺数据
	  * @author soul 2017/6/16
	  */
	function initNewShopData()
	{
		$Params = mvc::$URL_PARAMS;
		$shopId = empty($Params['shopId']) ? 0: trim($Params['shopId']);
		if($shopId > 0)
		{	
			// 给这个店铺增加四个会员等级
			$B2cShop = new B2cShop();
			$B2cShop->autoAddmemberLevel($shopId);		
		}
		echo 'ok';
	}


	/**
	  * @method 系统自动关闭24小时内未付款的订单
	  * @author soul 2017/6/16
	  */
	function autoCloseOrder()
	{
		$B2cOrder = new B2cOrder();
		$B2cOrder->autoCloseOrder();
		echo 'ok';
	}

	/**
	  * @method 系统自动检测已付款，但是订单状态还是待付款
	  * @author soul 2017/6/16
	  */
	function autoPayOrder()
	{
		$B2cOrder = new B2cOrder();
		$B2cOrder->autoPayOrder();
		echo 'ok';
	}


	/**
	  * @method 系统自动检测检测退款状态
	  * @author soul 2017/6/16
	  */
	function autoOrderRefundStatus()
	{
		$B2cOrder = new B2cOrder();
		$B2cOrder->autoOrderRefundStatus();
		echo 'ok';
	}

	/**
	  * @method 系统自动检测检测退款状态
	  * @author soul 2017/6/16
	  */
	function autoOkOrder()
	{
		$B2cOrder = new B2cOrder();
		$B2cOrder->autoOkOrder();
		echo 'ok';
	}


	/**
	  * @method 系统自动检测检测退款状态
	  * @author soul 2017/6/16
	  */
	function autoTiXian()
	{
		$B2cBase = new B2cBase();
		$res = $B2cBase->get('sh_money_withdrawals', ['mow_id'], sprintf(" and mow_status=0"));
		if(!empty($res['data']))
		{
			$B2cMoney = new B2cMoney();
			foreach($res['data'] as $v)
			{
				$B2cMoney->autoShopMoneyWithdrawals($v['mow_id']);
			}
		}
		echo 'ok';
	}


	

}

