diff --git a/api/controllers/plan/Items.php b/api/controllers/plan/Items.php
new file mode 100644
index 00000000..1d6ee85f
--- /dev/null
+++ b/api/controllers/plan/Items.php
@@ -0,0 +1,91 @@
+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 '
执行到当前客户id:' . $redis->get($redisKey);
+ echo '日期:' . json_encode(array('log_date' => $log_date), JSON_UNESCAPED_UNICODE);
+ echo '
成功新增:
';
+ if ($log) {
+ echo json_encode($log, JSON_UNESCAPED_UNICODE);
+ echo '
';
+ }
+ echo '数据库获取:
';
+ echo json_encode($res_ite, JSON_UNESCAPED_UNICODE);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/api/controllers/plan/Licheb.php b/api/controllers/plan/Licheb.php
index 0ff3bc95..125dcf76 100644
--- a/api/controllers/plan/Licheb.php
+++ b/api/controllers/plan/Licheb.php
@@ -18,90 +18,6 @@ class Licheb extends HD_Controller
$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 '
执行到当前id:' . $id;
- echo '
成功更新:
';
- if ($log) {
- echo json_encode($log, JSON_UNESCAPED_UNICODE);
- echo '
';
- }
- echo '数据库获取:
';
- 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:给销售发送待回访短信
* Created on: 2021/10/19 17:15
diff --git a/api/controllers/plan/Plan.php b/api/controllers/plan/Plan.php
index 82096a21..e564e619 100644
--- a/api/controllers/plan/Plan.php
+++ b/api/controllers/plan/Plan.php
@@ -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', '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', 'order', 'up_old_status')), 'interval' => 30); //更新旧订单状态
diff --git a/api/controllers/plan/Temp.php b/api/controllers/plan/Temp.php
index c3bcb898..7e909350 100644
--- a/api/controllers/plan/Temp.php
+++ b/api/controllers/plan/Temp.php
@@ -16,6 +16,90 @@ class Temp extends HD_Controller
$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 '
执行到当前id:' . $id;
+ echo '
成功更新:
';
+ if ($log) {
+ echo json_encode($log, JSON_UNESCAPED_UNICODE);
+ echo '
';
+ }
+ echo '数据库获取:
';
+ 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:更新客户初始销售
* Created on: 2022/3/09 11:58
diff --git a/common/models/items/Items_stock_log_model.php b/common/models/items/Items_stock_log_model.php
new file mode 100644
index 00000000..e1db0bdd
--- /dev/null
+++ b/common/models/items/Items_stock_log_model.php
@@ -0,0 +1,18 @@
+table_name, 'default');
+ }
+
+}
\ No newline at end of file