123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032 |
- <?php
- namespace Shop\Lib;
- use Dever;
- class Cron
- {
- # 定时更新银联账户余额信息
- public function yspay_account_api()
- {
- # 获取有银联商户号的门店
- $where = array();
- $mid = Dever::input('mid');
- if ($mid) {
- $where['mid'] = $mid;
- }
- $shop_id = Dever::input('shop_id');
- if ($shop_id) {
- $where['id'] = $shop_id;
- }
- $test = Dever::input('test');
- $shop = Dever::db('shop/info')->select($where);
- if (!$shop) {
- return 'error';
- }
- foreach ($shop as $k => $v) {
- if ($v['type'] == 10) {
- $v['mid'] = '89810007372106N';
- }
- if ($v['mid']) {
- $data = Dever::load('shop/yspay')->query_action($v['mid']);
- if ($test == 1) {
- print_r($data);die;
- }
- if ($data <= 0) {
- continue;
- }
- $update = array();
- $update['shop_id'] = $v['id'];
- $update['clear'] = true;
- $info = Dever::db('shop/yspay_account')->one($update);
- $update['cash'] = $data;
- $update['sdate'] = time();
- $update['mid'] = $v['mid'];
- if (!$info) {
- Dever::db('shop/yspay_account')->insert($update);
- } else {
- $update['where_id'] = $info['id'];
- Dever::db('shop/yspay_account')->update($update);
- }
- }
- }
- return 'ok';
- }
- # 定时获取银联提现信息
- public function yspay_tixian_api()
- {
- $num = Dever::input('num', 1);
-
- $start = Dever::input('start', date('Ymd', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Ymd'));
- # 获取有银联商户号的门店
- $where = array();
- $mid = Dever::input('mid');
- if ($mid) {
- $where['mid'] = $mid;
- }
- $shop_id = Dever::input('shop_id');
- if ($shop_id) {
- $where['id'] = $shop_id;
- }
- $test = Dever::input('test');
- $shop = Dever::db('shop/info')->select($where);
- if (!$shop) {
- return 'error';
- }
- foreach ($shop as $k => $v) {
- if ($v['type'] == 10) {
- $v['mid'] = '89810007372106N';
- }
- if ($v['mid']) {
- $data = Dever::load('shop/yspay')->record_action($v['mid'], $start, $end);
- if ($data) {
- if ($test == 1) {
- print_r($data);die;
- }
- foreach ($data as $k1 => $v1) {
- $update = array();
- $update['shop_id'] = $v['id'];
- $update['type'] = $v1['trxTypeDtl'];
- $update['tdate'] = Dever::maketime($v1['trxTime']);
- $update['mid'] = $v1['mchntNo'];
- $update['cardNo'] = $v1['cardNo'];
- $update['order_num'] = $v1['sysOrderId'];
- $update['status'] = $v1['status'];
- $update['clear'] = true;
- $info = Dever::db('shop/yspay_tixian')->one($update);
- $update['cash'] = $v1['transAmt'];
- if (!$info) {
- Dever::db('shop/yspay_tixian')->insert($update);
- } else {
- $update['where_id'] = $info['id'];
- Dever::db('shop/yspay_tixian')->update($update);
- }
- $account_data = array();
- $account_data['shop_id'] = $v['id'];
- $account_data['clear'] = true;
- $account = Dever::db('shop/yspay_account')->one($account_data);
- $total = Dever::db('shop/yspay_tixian')->getTotal(array('shop_id' => $v['id'], 'status' => 4));
- if ($total) {
- $account_data['tx_cash'] = $total['cash'];
- }
- if (!$account) {
- $account_data['mid'] = $v1['mchntNo'];
- Dever::db('shop/yspay_account')->insert($account_data);
- } else {
- $account_data['where_id'] = $account['id'];
- Dever::db('shop/yspay_account')->update($account_data);
- }
- }
- }
- }
- }
- return 'ok';
- }
- # 定时更新店铺经纬度
- public function geo_api()
- {
- Dever::config('base')->hook = true;
- $shop = Dever::db('shop/info')->select();
- if ($shop) {
- foreach ($shop as $k => $v) {
- $temp = explode(',', $v['area']);
- if (isset($temp[1]) && $v['address']) {
- $geo = Dever::load('shop/lib/info')->geo($temp[1], $v['address']);
- $update['lng'] = $geo[0];
- $update['lat'] = $geo[1];
- $update['map'] = $geo[2];
- $update['coord_address'] = $v['address'];
- $update['where_id'] = $v['id'];
- Dever::db('shop/info')->update($update);
- }
- }
- }
- return 'ok';
- }
- # 同步退款状态
- public function refund_status_api()
- {
- $order = Dever::db('shop/sell_order')->select();
- foreach ($order as $k => $v) {
- if ($v['refund_cash'] > 0) {
- if ($v['status'] == 6 || $v['status'] == 8) {
- $status = 4;
- } else {
- $status = 3;
- }
- } elseif ($v['refund_status'] == 2) {
- $status = 2;
- } else {
- $status = 1;
- }
- Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'refund_status' => $status));
- }
- $order = Dever::db('shop/buy_order')->select();
- foreach ($order as $k => $v) {
- if ($v['refund_cash'] > 0) {
- if ($v['status'] == 6 || $v['status'] == 8) {
- $status = 4;
- } else {
- $status = 3;
- }
- } elseif ($v['refund_status'] == 2) {
- $status = 2;
- } else {
- $status = 1;
- }
- Dever::db('shop/buy_order')->update(array('where_id' => $v['id'], 'refund_status' => $status));
- }
- }
- # 获取7天后完成的订单 准备分账
- public function yspay_api()
- {
- $day = Dever::input('day', 7);
- $time = time();
- $where['status'] = '5,6';
- $where['withdraw'] = 1;
- $where['cdate'] = $time - $day*86400;
- $order = Dever::db('shop/sell_order')->getDataByTime($where);
- if ($order) {
- foreach ($order as $k => $v) {
- $this->yspayOne($v);
- }
- }
- }
- public function yspayOne($v)
- {
- $shop = Dever::db('shop/info')->find($v['shop_id']);
- if ($v['withdraw'] == 1 && $shop && $shop['mid'] && $shop['status'] == 1) {
- if ($v['refund_cash']) {
- $v['price'] -= $v['refund_cash'];
- $v['price'] = round($v['price'], 2);
- }
- if ($v['price'] > 0) {
- $cash = $v['price'] * 100;//之后还要加上礼品卡的钱
- $v['desc'] = '系统自动提现';
- $v['mtype'] = 1;
- Dever::load('shop/yspay')->action($shop['mid'], $v['order_num'], $v['id'], 2, $cash, $v);
- sleep(1);
- } else {
- Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'withdraw' => 2));
- }
- }
- }
- public function setGoodsStatus_api()
- {
- $goods = Dever::db('goods/info')->select();
- if ($goods) {
- foreach ($goods as $k => $v) {
- Dever::db('shop/goods')->updates(array('option_goods_id' => $v['id'], 'set_status' => $v['status']));
- Dever::db('store/goods')->updates(array('option_goods_id' => $v['id'], 'set_status' => $v['status']));
- Dever::db('factory/goods')->updates(array('option_goods_id' => $v['id'], 'set_status' => $v['status']));
- }
- }
- }
- /**
- * 处理优惠券到期时间
- *
- * @return mixed
- */
- public function coupon_api()
- {
- $coupon = Dever::db('shop/user_coupon')->getAll(array('status' => 1, 'edate' => time() - 86400));
- if ($coupon && Dever::project('message')) {
- foreach ($coupon as $k => $v) {
- $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
- $msg = $coupon_info['name'] . ",要到期啦!";
- $msg_param['type'] = 2;//消息类型2是优惠券
- $msg_param['id'] = $v['id'];
- $msg_param['coupon_id'] = $v['coupon_id'];
- $msg_param = Dever::json_encode($msg_param);
- Dever::load('message/lib/data')->push(-1, $v['uid'], '优惠劵到期提醒', $msg, 4, 1, false, $msg_param);
- if (Dever::load('wechat_applet') && $v['uid'] && $v['uid'] > 0) {
- $user = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'system_id' => 1, 'system_source' => 5));
- if ($user && $user['openid']) {
- $send = array
- (
- 'thing1' => array
- (
- 'value' => $coupon_info['name'],
- ),
- 'time2' => array
- (
- 'value' => date('Y-m-d H:i', $v['edate']),
- ),
- 'thing3' => array
- (
- 'value' => '您有一张优惠券即将到期,请尽快使用',
- ),
- );
- $send = Dever::json_encode($send);
- Dever::load('wechat_applet/subscribe')->sendOne('act_2', 1, $user['openid'], 'pages/my/coupon/coupon', $send, Dever::config('base')->wechat_applet);
- }
- }
- }
- }
- }
- /**
- * 处理待支付订单提醒
- *
- * @return mixed
- */
- public function order_api()
- {
- # 获取超过5分钟未支付的订单
- $time = time();
- $where['status'] = 1;
- $where['cdate'] = $time - 300;
- $order = Dever::db('shop/sell_order')->getDataByTime($where);
- if ($order && Dever::project('message')) {
- $config = Dever::db('shop/sell_order')->config;
- foreach ($order as $k => $v) {
- if ($time - $v['cdate'] >= 900) {
- Dever::load('shop/lib/sell')->set(1, 2)->cancel($v['uid'], $v['id'], 11);
- Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'status' => 11, 'notice' => 2));
- } elseif ($v['notice'] == 1) {
- Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'notice' => 2));
- $msg = "您有一笔待付款订单,请及时付款。\r\n订单15分钟内未付款自动取消~";
- $shop = Dever::db('shop/info')->one($v['shop_id']);
- $msg_param = array();
- $msg_param['type'] = 1;//消息类型1是订单消息
- $msg_param['id'] = $v['id'];
- $msg_param['name'] = $shop['name'];
- $msg_param = Dever::json_encode($msg_param);
- Dever::load('message/lib/data')->push(-1, $v['uid'], '订单待支付提醒', $msg, 2, 1, false, $msg_param);
- if (Dever::load('wechat_applet') && $v['uid'] && $v['uid'] > 0) {
- $user = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'system_id' => 1, 'system_source' => 5));
- if ($user && $user['openid']) {
- $v['status_name'] = $config['status'][$v['status']];
- $send = array
- (
- 'character_string5' => array
- (
- 'value' => $v['order_num'],
- ),
- 'amount11' => array
- (
- 'value' => $v['price'] . '元',
- ),
- 'phrase13' => array
- (
- 'value' => $v['status_name'],
- ),
- 'thing12' => array
- (
- 'value' => '您有一笔待付款订单,请及时付款。',
- ),
- );
- $send = Dever::json_encode($send);
- Dever::load('wechat_applet/subscribe')->sendOne('order_pay', 1, $user['openid'], 'pages/app/order/order?id=' . $v['id'], $send, Dever::config('base')->wechat_applet);
- }
- }
- }
- }
- }
- }
- /**
- * 处理待支付订单提醒
- *
- * @return mixed
- */
- public function buy_order_api()
- {
- $time = time();
- $where['status'] = 1;
- $where['cdate'] = $time - 7200;
- $order = Dever::db('shop/buy_order')->getDataByTime($where);
- if ($order) {
- foreach ($order as $k => $v) {
- Dever::load('mshop/lib/buy')->set(1, 1)->cancel($v['type_id'], $v['id']);
- Dever::db('shop/buy_order')->update(array('where_id' => $v['id'], 'status' => 11));
- }
- }
- }
- /**
- * 处理销售数据 生成每天的销量统计
- *
- * @return mixed
- */
- public function sell_api()
- {
- $num = Dever::input('num', 1);
- $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Y-m-d'));
- $where['status'] = '2,3,4,5,6';
- $start = Dever::maketime($start . ' 00:00:00');
- $end = Dever::maketime($end . ' 23:59:59');
- $day = intval(($end - $start)/86400);
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where['shop_id'] = $v['id'];
- for($i=0; $i<=$day; $i++) {
- $where['start'] = $start + 86400*$i;
- $where['end'] = $start + 86400*$i + 86399;
- $data = array();
- $data['shop_id'] = $v['id'];
- $data['day'] = $where['start'];
- $info = Dever::db('shop/sell_stat')->find($data);
- $cash = Dever::db('shop/sell_order')->getCashNum($where);
- $data['cash'] = round($cash['total'], 2);
- $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
-
- if ($data['order'] > 0) {
- $goods = Dever::db('shop/sell_order')->getGoodsNum($where);
- $data['goods'] = $goods['total'];
- $data['area'] = $v['area'];
- $data['province'] = $v['province'];
- $data['city'] = $v['city'];
- $data['county'] = $v['county'];
- $data['town'] = $v['town'];
- if (!$info) {
- Dever::db('shop/sell_stat')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/sell_stat')->update($data);
- }
- }
- }
- }
- }
- public function buy_api()
- {
- $num = Dever::input('num', 30);
- $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Y-m-d'));
- $where['status'] = '2,3,4,5,6';
- $start = Dever::maketime($start . ' 00:00:00');
- $end = Dever::maketime($end . ' 23:59:59');
- $day = intval(($end - $start)/86400);
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where['type'] = 1;
- $where['type_id'] = $v['id'];
- for($i=0; $i<=$day; $i++) {
- $where['start'] = $start + 86400*$i;
- $where['end'] = $start + 86400*$i + 86399;
- $data = array();
- $data['shop_id'] = $v['id'];
- $data['day'] = $where['start'];
- $info = Dever::db('shop/buy_stat')->find($data);
- $cash = Dever::db('shop/buy_order_goods')->getCashNum($where);
- $data['cash'] = round($cash['total'], 2);
- $cash = Dever::db('shop/buy_order_goods')->getPCashNum($where);
- $data['p_cash'] = round($cash['total'], 2);
- $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
- if ($data['order'] > 0) {
- $goods = Dever::db('shop/buy_order')->getGoodsNum($where);
- $data['goods'] = $goods['total'];
- $data['area'] = $v['area'];
- $data['province'] = $v['province'];
- $data['city'] = $v['city'];
- $data['county'] = $v['county'];
- $data['town'] = $v['town'];
- if (!$info) {
- Dever::db('shop/buy_stat')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/buy_stat')->update($data);
- }
- }
- }
- }
- return 'ok';
- }
- /**
- * 门店数据统计
- *
- * @return mixed
- */
- public function shop_api()
- {
- $num = Dever::input('num', 1);
- $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Y-m-d'));
- $start = Dever::maketime($start . ' 00:00:00');
- $end = Dever::maketime($end . ' 23:59:59');
- $day = intval(($end - $start)/86400);
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where = array();
- $where['status'] = '2,3,4,5,6';
- $where['shop_id'] = $v['id'];
- for($i=0; $i<=$day; $i++) {
- $where['start'] = $start + 86400*$i;
- $where['end'] = $start + 86400*$i + 86399;
- $data = array();
- $data['shop_id'] = $v['id'];
- $data['day'] = $where['start'];
- $info = Dever::db('shop/shop_stat')->find($data);
- $cash = Dever::db('shop/sell_order')->getCashNum($where);
- $data['sell_cash'] = round($cash['total'], 2);
- $data['sell_num'] = Dever::db('shop/sell_order')->getOrderNum($where);
-
- $where['type'] = 1;
- $where['type_id'] = $v['id'];
- $cash = Dever::db('shop/buy_order_goods')->getCashNum($where);
- $data['buy_cash'] = round($cash['total'], 2);
- $data['buy_num'] = Dever::db('shop/buy_order')->getOrderNum($where);
- $data['sl_num'] = 0;
- $data['area'] = $v['area'];
- $data['province'] = $v['province'];
- $data['city'] = $v['city'];
- $data['county'] = $v['county'];
- $data['town'] = $v['town'];
- if ($data['buy_num'] > 0) {
- if (!$info) {
- Dever::db('shop/shop_stat')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/shop_stat')->update($data);
- }
- }
- }
- }
- }
- /**
- * 商品数据统计
- *
- * @return mixed
- */
- public function goods_api()
- {
- $num = Dever::input('num', 5);
- $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Y-m-d'));
- $where['status'] = '2,3,4,5,6';
- $start = Dever::maketime($start . ' 00:00:00');
- $end = Dever::maketime($end . ' 23:59:59');
- $day = intval(($end - $start)/86400);
- for($i=0; $i<=$day; $i++) {
- $where['start'] = $start + 86400*$i;
- $where['end'] = $start + 86400*$i + 86399;
- $num = Dever::db('shop/sell_order_goods')->getNum($where);
- if ($num) {
- foreach ($num as $k => $v) {
- $data = array();
- $data['shop_id'] = $v['shop_id'];
- $data['goods_id'] = $v['goods_id'];
- $data['day'] = $where['start'];
- $info = Dever::db('shop/goods_stat')->find($data);
- $shop = Dever::db('shop/info')->find($data['shop_id']);
- if ($shop) {
- $data['area'] = $shop['area'];
- }
- $goods_info = Dever::db('goods/info')->find($data['goods_id']);
- if ($goods_info) {
- $data['category'] = $goods_info['category'];
- }
-
- $data['cash'] = round($v['cash'], 2);
- $data['num'] = round($v['num'], 2);
- if (!$info) {
- Dever::db('shop/goods_stat')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/goods_stat')->update($data);
- }
- }
- }
- }
- return 'ok';
- }
- /**
- * 门店数据统计
- *
- * @return mixed
- */
- public function user_api()
- {
- $num = Dever::input('num', 1);
- $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Y-m-d'));
- $start = Dever::maketime($start . ' 00:00:00');
- $end = Dever::maketime($end . ' 23:59:59');
- $day = intval(($end - $start)/86400);
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where = array();
- $where['status'] = '2,3,4,5,6';
- $where['shop_id'] = $v['id'];
- for($i=0; $i<=$day; $i++) {
- $where['start'] = $start + 86400*$i;
- $where['end'] = $start + 86400*$i + 86399;
- $data = array();
- $data['shop_id'] = $v['id'];
- $data['day'] = $where['start'];
- $info = Dever::db('shop/user_stat')->find($data);
- $total = Dever::db('shop/sell_order')->getUser($where);
- $data['total'] = count($total);
- foreach ($total as $k1 => $v1) {
- if ($v1['total'] <= 1) {
- unset($total[$k1]);
- }
- }
- $data['num'] = count($total);
- $data['order_num'] = Dever::db('shop/sell_order')->getOrderNum($where);
-
- if ($data['num'] > 0 || $data['order_num'] > 0) {
- $data['area'] = $v['area'];
- if (!$info) {
- Dever::db('shop/user_stat')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/user_stat')->update($data);
- }
- }
- }
- }
- }
- /**
- * 用户排名统计
- *
- * @return mixed
- */
- public function user_rank_api()
- {
- $num = Dever::input('num', 1);
- $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Y-m-d'));
- $start = Dever::maketime($start . ' 00:00:00');
- $end = Dever::maketime($end . ' 23:59:59');
- $day = intval(($end - $start)/86400);
- $w['start'] = $start;
- $w['end'] = $end;
- $w['status'] = '2,3,4,5,6';
- $data = Dever::db('shop/sell_order')->getAllByDate($w);
- if ($data) {
- $where = array();
- $result = array();
- foreach ($data as $k => $v) {
- $day = Dever::maketime(date('Y-m-d 00:00:00', $v['cdate']));
- $key = $v['shop_id'] . '_' . $day . '_' . $v['mobile'];
- if (!isset($result[$key])) {
- $result[$key] = array();
- $result[$key]['num'] = 0;
- $result[$key]['cash'] = 0;
- }
- $result[$key]['num'] += $v['num'];
- $result[$key]['cash'] = $v['total'];
- }
- if ($result) {
- foreach ($result as $k => $v) {
- $temp = explode('_', $k);
- $where['shop_id'] = $temp[0];
- $where['day'] = $temp[1];
- $where['mobile'] = $temp[2];
- $where['clear'] = true;
- $info = Dever::db('shop/user_rank_stat')->find($where);
- $up = array();
- if (!$info) {
- $up = $where;
- $shop = Dever::db('shop/info')->one($where['shop_id']);
- $up['area'] = $shop['area'];
- $up['num'] = $v['num'];
- $up['cash'] = $v['cash'];
- Dever::db('shop/user_rank_stat')->insert($up);
- } else {
- $up = array();
- $up['where_id'] = $info['id'];;
- $up['num'] = $v['num'];
- $up['cash'] = $v['cash'];
- Dever::db('shop/user_rank_stat')->update($up);
- }
- }
- }
- }
- }
- # 获取下单用户量
- public function order_user($where)
- {
- $where['status'] = '1,2,3,4,5,6';
- $user = Dever::db('shop/sell_order')->getUser($where);
- return $user;
- }
- # 处理月度对账数据 废弃,直接用结算单处理
- public function sell_month_api()
- {
- return;
- $num = Dever::input('num', -1);
- if ($num > 0) {
- $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
- } else {
- $month = Dever::input('start', date('Y-m'));
- }
- $where['status'] = 2;
- $start = Dever::maketime($month . '-01 00:00:00');
- $end = Dever::maketime($month . '-31 23:59:59');
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where['shop_id'] = $v['id'];
- $where['start'] = $start;
- $where['end'] = $end;
- $data = array();
- $data['shop_id'] = $v['id'];
- $data['month'] = $start;
- $info = Dever::db('shop/sell_stat_month')->find($data);
- $data['cash'] = Dever::db('shop/sell_order')->getCashNum($where);
- $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
- $data['goods'] = Dever::db('shop/sell_order')->getGoodsNum($where);
- if (!$info) {
- Dever::db('shop/sell_stat_month')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/sell_stat_month')->update($data);
- }
- }
- }
- # 处理月度对账数据:门店采购 废弃,直接用结算单处理
- public function buy_month_api()
- {
- return;
- $num = Dever::input('num', -1);
- if ($num > 0) {
- $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
- } else {
- $month = Dever::input('start', date('Y-m'));
- }
- $where['status'] = '5,6';
- $start = Dever::maketime($month . '-01 00:00:00');
- $end = Dever::maketime($month . '-31 23:59:59');
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where['type'] = 1;
- $where['type_id'] = $v['id'];
- $where['start'] = $start;
- $where['end'] = $end;
- $data = array();
- $data['shop_id'] = $v['id'];
- $data['month'] = $start;
- $info = Dever::db('shop/buy_stat_month')->find($data);
- $data['cash'] = Dever::db('shop/buy_order_goods')->getCashNum($where);
- $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
- $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
- if (!$info) {
- Dever::db('shop/buy_stat_month')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/buy_stat_month')->update($data);
- }
- }
- }
- # 处理月度对账数据:仓库对账 废弃,直接用结算单处理
- public function store_month_api()
- {
- return;
- $num = Dever::input('num', -1);
- if ($num > 0) {
- $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
- } else {
- $month = Dever::input('start', date('Y-m'));
- }
- $where['status'] = '5,6';
- $start = Dever::maketime($month . '-01 00:00:00');
- $end = Dever::maketime($month . '-31 23:59:59');
- $store = Dever::db('store/info')->select();
- foreach ($store as $k => $v) {
- $where['type'] = 2;
- $where['type_id'] = $v['id'];
- $where['start'] = $start;
- $where['end'] = $end;
- $data = array();
- $data['store_id'] = $v['id'];
- $data['month'] = $start;
- $info = Dever::db('shop/store_stat_month')->find($data);
- $data['cash'] = Dever::db('shop/buy_order_goods')->getCashNum($where);
- $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
- $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
- if (!$info) {
- Dever::db('shop/store_stat_month')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/store_stat_month')->update($data);
- }
- }
- }
- # 处理月度对账数据:工厂对账 废弃,直接用结算单处理
- public function factory_month_api()
- {
- return;
- $num = Dever::input('num', -1);
- if ($num > 0) {
- $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
- } else {
- $month = Dever::input('start', date('Y-m'));
- }
- $where['status'] = '5,6';
- $start = Dever::maketime($month . '-01 00:00:00');
- $end = Dever::maketime($month . '-31 23:59:59');
- $factory = Dever::db('factory/info')->select();
- foreach ($factory as $k => $v) {
- $where['source_type'] = 3;
- $where['source_id'] = $v['id'];
- $where['start'] = $start;
- $where['end'] = $end;
- $data = array();
- $data['factory_id'] = $v['id'];
- $data['month'] = $start;
- $info = Dever::db('shop/factory_stat_month')->find($data);
- $data['cash'] = Dever::db('shop/buy_order_goods')->getCashNum($where);
- $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
- $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
- if (!$info) {
- Dever::db('shop/factory_stat_month')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/factory_stat_month')->update($data);
- }
- }
- }
- # 校正出厂价
- public function setPrice_api()
- {
- $data = Dever::db('shop/buy_order')->select();
- if ($data) {
- foreach ($data as $k => $v) {
- $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
- if ($goods) {
- $p_price = 0;
- foreach ($goods as $v1) {
- $p_price += ($v1['p_price'] * $v1['num']);
- }
- Dever::db('shop/buy_order')->update(array('where_id' => $v['id'], 'p_price' => $p_price));
- }
- }
- }
- return 'ok';
- }
- #新增
- #平台商城订单表同步发货时间sell_order
- public function tongSellOrder_api()
- {
- $data = Dever::db('shop/sell_order')->state();
- foreach ($data as $k => $v) {
- if (isset($v['id']) && $v['id'] ) {
- $ps = Dever::db('shop/sell_order_ps')->find(array('order_id'=>$v['id']));
- $where['where_id'] = $v['id'];
- if (isset($ps) && $ps && isset($ps['cdate']) && $ps['cdate']) {
- $where['fadate'] = $ps['cdate'];
- Dever::db('shop/sell_order')->update($where);
- }
- }
- }
- }
- #门店采购发货时间
- public function tongBuyOrder_api()
- {
- $data = Dever::db('shop/buy_order')->state();
- foreach ($data as $k => $v) {
- if (isset($v['id']) && $v['id']) {
- $ps = Dever::db('shop/buy_order_ps')->find(array('order_id'=>$v['id']));
- $where['where_id'] = $v['id'];
- if (isset($ps) && $ps && isset($ps['cdate']) && $ps['cdate']) {
- $where['fadate'] = $ps['cdate'];
- Dever::db('shop/buy_order')->update($where);
- if ($v['parent_type'] == 2 && $v['parent_order_id'] > 0) {
- Dever::db('shop/sell_order')->update(array('where_id' => $v['parent_order_id'], 'fadate' => $ps['cdate']));
- $sell_order_ps = Dever::db('shop/sell_order_ps')->select(array('order_id'=>$v['parent_order_id']));
- if ($sell_order_ps) {
- foreach ($sell_order_ps as $k1 => $v1) {
- Dever::db('shop/sell_order_ps')->update(array('where_id' => $v1['id'], 'cdate' => $ps['cdate']));
- }
- }
- }
- }
- }
- }
- }
- # 处理配送服务商和配送时间
- public function upPs_api()
- {
- $where = array();
- $order_id = Dever::input('order_id');
- if ($order_id) {
- $where['order_id'] = $order_id;
- }
- /*
- $data = Dever::db('shop/buy_order_ps')->state($where);
- if ($data) {
- $update = array();
- foreach ($data as $k => $v) {
- $service = Dever::array_decode($v['service']);
- if ($service) {
- $update['service'] = array();
- foreach ($service as $k1 => $v1) {
- $update['service'][$k1] = $v1;
- if (isset($v1['service_id']) && $v1['service_id']) {
- $service_id = $v1['service_id'];
- $service_info = Dever::db('shop/service')->one($service_id);
- if ($service_info) {
- $service_new_info = Dever::db('shop/service')->getOne(array('name' => $service_info['name']));
- if ($service_new_info && $service_new_info['id'] != $service_id) {
- $update['service'][$k1]['service_id'] = $service_new_info['id'];
- Dever::db('shop/service')->update(array('where_id' => $service_info['id'], 'state' => 2));
- }
- }
- }
- }
- if ($update['service']) {
- $update['service'] = Dever::array_encode($update['service']);
- $update['where_id'] = $v['id'];
- Dever::db('shop/buy_order_ps')->update($update);
- }
- }
- }
- }
- if ($order_id) {
- return 'ok';
- }
- $data = Dever::db('shop/sell_order_ps')->state();
- if ($data) {
- $update = array();
- foreach ($data as $k => $v) {
- $service = Dever::array_decode($v['service']);
- if ($service) {
- $update['service'] = array();
- foreach ($service as $k1 => $v1) {
- $update['service'][$k1] = $v1;
- if (isset($v1['service_id']) && $v1['service_id']) {
- $service_id = $v1['service_id'];
- $service_info = Dever::db('shop/service')->one($service_id);
- if ($service_info) {
- $service_new_info = Dever::db('shop/service')->getOne(array('name' => $service_info['name']));
- if ($service_new_info && $service_new_info['id'] != $service_id) {
- $update['service'][$k1]['service_id'] = $service_new_info['id'];
- Dever::db('shop/service')->update(array('where_id' => $service_info['id'], 'state' => 2));
- }
- }
- }
- }
- if ($update['service']) {
- $update['service'] = Dever::array_encode($update['service']);
- $update['where_id'] = $v['id'];
- Dever::db('shop/sell_order_ps')->update($update);
- }
- }
- }
- }
- */
- $data = Dever::db('agent/dh_order_ps')->state();
- if ($data) {
- $update = array();
- foreach ($data as $k => $v) {
- $service = Dever::array_decode($v['service']);
- if ($service) {
- $update['service'] = array();
- foreach ($service as $k1 => $v1) {
- $update['service'][$k1] = $v1;
- if (isset($v1['service_id']) && $v1['service_id']) {
- $service_id = $v1['service_id'];
- $service_info = Dever::db('shop/service')->one($service_id);
- if ($service_info) {
- $service_new_info = Dever::db('shop/service')->getOne(array('name' => $service_info['name']));
- if ($service_new_info && $service_new_info['id'] != $service_id) {
- $update['service'][$k1]['service_id'] = $service_new_info['id'];
- Dever::db('shop/service')->update(array('where_id' => $service_info['id'], 'state' => 2));
- }
- }
- }
- }
- if ($update['service']) {
- $update['service'] = Dever::array_encode($update['service']);
- $update['where_id'] = $v['id'];
- Dever::db('agent/dh_order_ps')->update($update);
- }
- }
- }
- }
- return 'ok';
- }
- }
|