stock_331

This commit is contained in:
dengbw
2022-03-31 11:40:27 +08:00
parent abae1d02ec
commit e39a810888
5 changed files with 194 additions and 84 deletions
+91
View File
@@ -0,0 +1,91 @@
<?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);
}
}
}
-84
View File
@@ -18,90 +18,6 @@ class Licheb extends HD_Controller
$this->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit'); $this->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit');
} }
/**
* Notes:更新车辆调拨状态
* Created on: 2022/2/28 17:15
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/licheb/inventory_log
* https://api.liche.cn/plan/licheb/inventory_log
*/
public function inventory_log()
{
$params = $this->input->get();
$size = 100;//每次最多处理多少条
$rds = intval($this->input->get('rds'));
$redis = &load_cache('redis');
$redisKey = 'inventory_log_id';
$id = $redis->get($redisKey);
!$id && $id = 0;
if ($rds) {//手动清除缓存
$id = 0;
$redis->delete($redisKey);
}
$log = array();
$this->load->model('items/Items_inventory_log_model', 'mdInventoryLog');
$this->load->model('items/items_model', 'mdItems');
$where = array('id >' => $id, 'status' => 0);
$res_log = $this->mdInventoryLog->select($where, 'id asc', 1, $size, 'id,item_id,biz_id,addr_id');
if (!$res_log) {
echo '执行到当前id' . $id . '暂无数据';
$redis->delete($redisKey);
return;
}
foreach ($res_log as $key => $value) {
$id = $value['id'];
$res_item = $this->mdItems->get(['id' => $value['item_id']]);
if ($res_item) {
$status = '';
if ($res_item['bill_time'] != '0000-00-00 00:00:00') {//已售
$status = -2;
} else if ($res_item['biz_id'] != $value['biz_id'] || $res_item['addr_id'] != $value['addr_id']) {//已调拨
$status = -1;
}
if ($status) {
$ret = $this->mdInventoryLog->update(['status' => $status], ['id' => $id]);
if ($ret) {
$log[] = array('id' => $id, 'status' => $status);
}
}
}
}
$redis->save($redisKey, $id);//保存最后id
if ($params['sd']) {
echo '<br>执行到当前id' . $id;
echo '<br>成功更新:<br>';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
echo '<br>';
}
echo '数据库获取:<br>';
echo json_encode($res_log, JSON_UNESCAPED_UNICODE);
}
}
/**
* Notes:更新车辆调拨异常
* Created on: 2022/1/4 13:53
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/licheb/transfer_abnormal
* https://api.liche.cn/plan/licheb/transfer_abnormal
*/
public function transfer_abnormal()
{
$this->load->model('items/items_transfer_model', 'mdTransfer');
$params = $this->input->get();
$ret = '';
if ($params['id']) {
$abnormal = intval($params['abnormal']);
$ret = $this->mdTransfer->update(['abnormal' => $abnormal], ['id' => $params['id']]);
}
if ($ret) {
echo "更新异常成功_{$params['id']}_$abnormal";
} else {
echo "更新异常失败";
}
}
/** /**
* Notes:给销售发送待回访短信 * Notes:给销售发送待回访短信
* Created on: 2021/10/19 17:15 * Created on: 2021/10/19 17:15
+1
View File
@@ -34,6 +34,7 @@ class Plan extends CI_Controller
$plan[] = array('url' => base_url(array('plan', 'licheb', 'visit_sales_sms')), 'interval' => 1);//给销售发送待回访短信 $plan[] = array('url' => base_url(array('plan', 'licheb', 'visit_sales_sms')), 'interval' => 1);//给销售发送待回访短信
$plan[] = array('url' => base_url(array('plan', 'licheb', 'customer_manager_sms')), 'interval' => 1);//给店长发送待分配短信 $plan[] = array('url' => base_url(array('plan', 'licheb', 'customer_manager_sms')), 'interval' => 1);//给店长发送待分配短信
$plan[] = array('url' => base_url(array('plan', 'licheb', 'customer_manager_sms')), 'interval' => 1);//给店长发送待分配短信 $plan[] = array('url' => base_url(array('plan', 'licheb', 'customer_manager_sms')), 'interval' => 1);//给店长发送待分配短信
$plan[] = array('url' => base_url(array('plan', 'items', 'stock_log')), 'interval' => 10);//库存车辆日志
$plan[] = array('url' => base_url(array('plan', 'biz', 'settle')), 'interval' => 1); $plan[] = array('url' => base_url(array('plan', 'biz', 'settle')), 'interval' => 1);
$plan[] = array('url' => base_url(array('plan', 'order', 'up_old_status')), 'interval' => 30); //更新旧订单状态 $plan[] = array('url' => base_url(array('plan', 'order', 'up_old_status')), 'interval' => 30); //更新旧订单状态
+84
View File
@@ -16,6 +16,90 @@ class Temp extends HD_Controller
$this->log_file = 'temp.log'; $this->log_file = 'temp.log';
} }
/**
* Notes:更新车辆调拨状态
* Created on: 2022/2/28 17:15
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/licheb/inventory_log
* https://api.liche.cn/plan/licheb/inventory_log
*/
public function inventory_log()
{
$params = $this->input->get();
$size = 100;//每次最多处理多少条
$rds = intval($this->input->get('rds'));
$redis = &load_cache('redis');
$redisKey = 'inventory_log_id';
$id = $redis->get($redisKey);
!$id && $id = 0;
if ($rds) {//手动清除缓存
$id = 0;
$redis->delete($redisKey);
}
$log = array();
$this->load->model('items/Items_inventory_log_model', 'mdInventoryLog');
$this->load->model('items/items_model', 'mdItems');
$where = array('id >' => $id, 'status' => 0);
$res_log = $this->mdInventoryLog->select($where, 'id asc', 1, $size, 'id,item_id,biz_id,addr_id');
if (!$res_log) {
echo '执行到当前id' . $id . '暂无数据';
$redis->delete($redisKey);
return;
}
foreach ($res_log as $key => $value) {
$id = $value['id'];
$res_item = $this->mdItems->get(['id' => $value['item_id']]);
if ($res_item) {
$status = '';
if ($res_item['bill_time'] != '0000-00-00 00:00:00') {//已售
$status = -2;
} else if ($res_item['biz_id'] != $value['biz_id'] || $res_item['addr_id'] != $value['addr_id']) {//已调拨
$status = -1;
}
if ($status) {
$ret = $this->mdInventoryLog->update(['status' => $status], ['id' => $id]);
if ($ret) {
$log[] = array('id' => $id, 'status' => $status);
}
}
}
}
$redis->save($redisKey, $id);//保存最后id
if ($params['sd']) {
echo '<br>执行到当前id' . $id;
echo '<br>成功更新:<br>';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
echo '<br>';
}
echo '数据库获取:<br>';
echo json_encode($res_log, JSON_UNESCAPED_UNICODE);
}
}
/**
* Notes:更新车辆调拨异常
* Created on: 2022/1/4 13:53
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/licheb/transfer_abnormal
* https://api.liche.cn/plan/licheb/transfer_abnormal
*/
public function transfer_abnormal()
{
$this->load->model('items/items_transfer_model', 'mdTransfer');
$params = $this->input->get();
$ret = '';
if ($params['id']) {
$abnormal = intval($params['abnormal']);
$ret = $this->mdTransfer->update(['abnormal' => $abnormal], ['id' => $params['id']]);
}
if ($ret) {
echo "更新异常成功_{$params['id']}_$abnormal";
} else {
echo "更新异常失败";
}
}
/** /**
* Notes:更新客户初始销售 * Notes:更新客户初始销售
* Created on: 2022/3/09 11:58 * Created on: 2022/3/09 11:58
@@ -0,0 +1,18 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Notes:库存车辆_日志
* Created on: 2022/3/30 16:43
* Created by: dengbw
*/
class Items_stock_log_model extends HD_Model
{
private $table_name = 'lc_items_stock_log';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
}