Files
2022-03-31 11:44:47 +08:00

91 lines
3.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Notes:车辆/商品数据操作
* Created on: 2022/3/30 17:15
* Created by: dengbw
*/
class Items extends HD_Controller
{
private $log_file;
public function __construct()
{
parent::__construct();
$this->log_file = 'items.log';
}
/**
* Notes:库存车辆_日志
* Created on: 2021/10/19 17:15
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/items/stock_log?sd=1
* https://api.liche.cn/plan/items/stock_log
*/
public function stock_log()
{
$params = $this->input->get();
$hour = date('H.i');
if (($hour > 23.30 && $hour < 23.59) || $params['sd']) {
if ($params['sd']) {
echo "开始执行库存车辆日志[{$hour}]";
}
} else {
echo '[23:30]过后才会开始执行库存车辆日志[' . $hour . ']';
return;
}
$this->load->model('items/items_stock_log_model', 'mdItemsStockLog');
$this->load->model('items/items_model', 'mdItems');
$this->load->model('items/items_transfer_model', 'mdTransfer');
$size = 150;//每次最多处理多少条
$rds = intval($this->input->get('rds'));
$redis = &load_cache('redis');
$redisKey = 'items_stock_log_item_id';
$log_date = date('Y-m-d');
$re_v = $this->mdItemsStockLog->get(array('log_date' => $log_date));//查找当天是否有数据
if (!$re_v || $rds) {
$redis->delete($redisKey);
}
$item_id = $redis->get($redisKey);
!$item_id && $item_id = 0;
$log = [];
$where = ['id >' => $item_id, 'biz_id >' => 0, 'status>' => 0, 'bill_time' => '0000-00-00 00:00:00'];
$res_ite = $this->mdItems->select($where, 'id asc', 1, $size, 'id,brand_id,s_id,biz_id,in_time');
if (!$res_ite) {
echo '执行到当前车辆id' . $item_id . '暂无数据';
return;
}
$addDate = [];
foreach ($res_ite as $key => $value) {
$item_id = $value['id'];
$re_ite = $this->mdItemsStockLog->get(array('log_date' => $log_date, 'item_id' => $value['id']));
if (!$re_ite) {//判断当天是否已加入
$in_time = $value['in_time'];
//查找调拨接车的门店
$re_tra = $this->mdTransfer->max('in_time', ["item_id" => $item_id, 'status' => 2, 'biz_id' => $value['biz_id']]);
$re_tra['in_time'] && $in_time = $re_tra['in_time'];//有调拨的接车时间,就是入库日期
$stay_days = round((time() - strtotime($in_time)) / 3600 / 24);
$addDate[] = ['item_id' => $item_id, 'brand_id' => $value['brand_id'], 's_id' => $value['s_id'],
'biz_id' => $value['biz_id'], 'in_time' => $in_time, 'log_date' => $log_date, 'stay_days' => $stay_days, 'c_time' => time()];
$log[] = array('item_id' => $item_id, 'stay_days' => $stay_days, 'in_time' => $in_time);
}
}
if ($addDate && count($addDate)) {
$this->mdItemsStockLog->add_batch($addDate);
}
$redis->save($redisKey, $item_id);//保存最后客户id
if ($params['sd']) {
echo '<br>执行到当前客户id' . $redis->get($redisKey);
echo '日期:' . json_encode(array('log_date' => $log_date), JSON_UNESCAPED_UNICODE);
echo '<br>成功新增:<br>';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
echo '<br>';
}
echo '数据库获取:<br>';
echo json_encode($res_ite, JSON_UNESCAPED_UNICODE);
}
}
}