|
@@ -0,0 +1,315 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Shop\Lib;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+
|
|
|
+class Record
|
|
|
+{
|
|
|
+
|
|
|
+ #生成订单号
|
|
|
+ public function getOrderId()
|
|
|
+ {
|
|
|
+ $where['order_num'] = Dever::order('R');
|
|
|
+ $where['clear'] = true;
|
|
|
+ $state = Dever::db('shop/record')->one($where);
|
|
|
+ if (!$state) {
|
|
|
+ return $where['order_num'];
|
|
|
+ } else {
|
|
|
+ return $this->getOrderId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function pingtai($shop_id,$sid,$type,$type_id,$price,$yue,$explan=false){
|
|
|
+ $where['shop_id'] = $shop_id;
|
|
|
+ $where['sid'] = $sid;
|
|
|
+ $where['type'] = $type;
|
|
|
+ $where['type_id'] = $type_id;
|
|
|
+ $where['price'] = $price;
|
|
|
+ $where['yue'] = $yue;
|
|
|
+ $where['order_num'] = $this->getOrderId();
|
|
|
+ if($explan){
|
|
|
+ $where['explan'] = $explan;
|
|
|
+ }
|
|
|
+ if($type == 4){
|
|
|
+ $where['explan'] = '采购商品';
|
|
|
+ }
|
|
|
+ $where['status'] = 2;
|
|
|
+ $where['state'] = 1;
|
|
|
+ $where['cdate'] = time();
|
|
|
+ // print_R($where);die;
|
|
|
+ $ids = Dever::db('shop/record')->insert($where);
|
|
|
+ return $ids;
|
|
|
+ }
|
|
|
+ #充值和提现
|
|
|
+ public function updateRecord($id,$name,$data){
|
|
|
+ $audit = Dever::input('audit',$data);
|
|
|
+ $sid = Dever::input('sid',$data);
|
|
|
+ $info = Dever::db('shop/record')->find($id);
|
|
|
+ $shop = Dever::db('shop/info')->find(array('sid'=>$info['sid']));
|
|
|
+ if ($info) {
|
|
|
+ $where['where_id'] = $shop['id'];
|
|
|
+ $where['price'] = $info['price'];
|
|
|
+ if($info['type'] ==2){
|
|
|
+ if($info['price']>$shop['price']){
|
|
|
+ Dever::alert('提现大于余额');
|
|
|
+ }
|
|
|
+ $where['price'] = 0;
|
|
|
+ $insert['yue'] = $shop['price'];
|
|
|
+ }
|
|
|
+ Dever::db('shop/info')->upCash($where);
|
|
|
+ $ids = Dever::db('shop/info')->find(array('sid'=>$info['sid'],'s'=>1));
|
|
|
+ if($info['type'] == 1){
|
|
|
+ $insert['yue'] = $ids['price'];
|
|
|
+ }
|
|
|
+ $insert['where_id'] = $info['id'];
|
|
|
+ $insert['shop_id'] = $shop['id'];
|
|
|
+ $insert['order_num'] = $this->getOrderId();
|
|
|
+ if($info['type'] == 1){
|
|
|
+ $insert['status'] = 2;
|
|
|
+ $insert['operdate'] = time();
|
|
|
+ }elseif($info['type'] == 2){
|
|
|
+ $insert['status'] = 1;
|
|
|
+ $insert['audit'] = 1;
|
|
|
+ $insert['fafang'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ Dever::db('shop/record')->update($insert);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #审核和发放
|
|
|
+ public function RecordAuditUpdate($id, $name, $data)
|
|
|
+ {
|
|
|
+ Dever::config('base')->hook = true;
|
|
|
+ $audit = Dever::param('audit', $data);
|
|
|
+ if ($audit > 1) {
|
|
|
+ $mul_type = Dever::config('base')->mul_type;
|
|
|
+ if ($mul_type == 2) {
|
|
|
+ $list = Dever::db('shop/record')->select(array('status' => 1));
|
|
|
+ } else {
|
|
|
+ $list = explode(',', $id);
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = Dever::db('shop/record')->find(array('id' => $id));
|
|
|
+ #已审核
|
|
|
+ if ($audit == 2) {
|
|
|
+ $shop = Dever::db('shop/info')->find($info['shop_id']);
|
|
|
+
|
|
|
+ $info = Dever::db('shop/record')->find($id);
|
|
|
+ if ($info) {
|
|
|
+ $where['where_id'] = $info['shop_id'];
|
|
|
+
|
|
|
+ if($info['type'] == 2){
|
|
|
+ if($info['price']>$shop['price']){
|
|
|
+ Dever::alert('提现大于余额');
|
|
|
+ }
|
|
|
+ $where['price'] = -1*$info['price'];
|
|
|
+
|
|
|
+ $yue = $shop['price'] + $where['price'];
|
|
|
+ Dever::db('shop/record')->update(array('where_id' => $id, 'yue'=>$yue,'status' => 2, 'operdate' => time()));
|
|
|
+ }else{
|
|
|
+ $where['price'] = $info['price'];
|
|
|
+ Dever::db('shop/record')->update(array('where_id' => $id, 'status' => 2, 'operdate' => time()));
|
|
|
+ }
|
|
|
+
|
|
|
+ Dever::db('shop/info')->upCash($where);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ #作废
|
|
|
+ Dever::db('shop/record')->update(array('where_id' => $id, 'status' => 3, 'operdate' => time()));
|
|
|
+ $info = Dever::db('shop/record')->find($id);
|
|
|
+ if ($info && $info['type'] == 2) {
|
|
|
+ $where['where_id'] = $info['shop_id'];
|
|
|
+ $where['cash'] = -1*$info['price'];
|
|
|
+ Dever::db('shop/info')->upCash($where);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #列表页展示
|
|
|
+ public function order_num($id){
|
|
|
+ $info = Dever::db('shop/record')->find($id);
|
|
|
+ $data = array();
|
|
|
+ $data['num'] = $info['order_num'].'<br/>'.date('Y-m-d H:i',$info['cdate']);
|
|
|
+ $shop = Dever::db('shop/info')->find($info['shop_id']);
|
|
|
+ $data['name'] = $shop['name'].'<br/>'.$shop['sid'];
|
|
|
+ $data['price'] = $info['price'].'<br/>'.$info['yue'];
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+ #详情页展示
|
|
|
+ public function show(){
|
|
|
+ $id = Dever::input('id');
|
|
|
+ $info = Dever::db('shop/record')->find($id);
|
|
|
+ $shop = Dever::db('shop/info')->find($info['shop_id']);
|
|
|
+ $typeconfig = Dever::db('shop/record')->config['config_type'];
|
|
|
+ $type = Dever::status($typeconfig,$info['type']);
|
|
|
+ $config = Dever::db('shop/record')->config['config_status'];
|
|
|
+ $status = Dever::status($config,$info['status']);
|
|
|
+ $operdate = '-';
|
|
|
+ if($info['operdate']){
|
|
|
+ $operdate = date('Y/m/d H:i',$info['operdate']);
|
|
|
+ }
|
|
|
+ $audit_name = '-';
|
|
|
+ if($info['audit'] == 1){
|
|
|
+ $audit_name = '待审核';
|
|
|
+ }elseif($info['audit'] == 2){
|
|
|
+ $audit_name = '已审核';
|
|
|
+ }else{
|
|
|
+ $audit_name = '已作废';
|
|
|
+ }
|
|
|
+ $f_name = '-';
|
|
|
+ if($info['fafang'] == 1){
|
|
|
+ $f_name = '待发放';
|
|
|
+ }elseif($info['fafang'] == 2){
|
|
|
+ $f_name = '已发放';
|
|
|
+ }else{
|
|
|
+ $f_name = '已作废';
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = array();
|
|
|
+ $result['门店信息'] = array
|
|
|
+ (
|
|
|
+ 'type' => 'info',
|
|
|
+ 'content' => array
|
|
|
+ (
|
|
|
+ array
|
|
|
+ (
|
|
|
+ array('门店名称', $shop['name']),
|
|
|
+ array('门店编号', $shop['sid']),
|
|
|
+ array('负责人', $shop['truename']),
|
|
|
+ array('联系电话', $shop['mobile']),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ $result['交易信息'] = array
|
|
|
+ (
|
|
|
+ 'type' => 'info',
|
|
|
+ 'content' => array
|
|
|
+ (
|
|
|
+ array
|
|
|
+ (
|
|
|
+ array('流水号', $info['order_num']),
|
|
|
+ array('交易时间', date('Y/m/d H:i',$info['cdate'])),
|
|
|
+ array('交易类型', $type),
|
|
|
+ array('交易状态', $status),
|
|
|
+ array('交易金额', $info['price']),
|
|
|
+ array('交易后金额', $info['yue']),
|
|
|
+ array('交易说明', $info['explan']),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ if($info['type'] == 2){
|
|
|
+ $result['提现信息'] = array
|
|
|
+ (
|
|
|
+ 'type' => 'info',
|
|
|
+ 'content' => array
|
|
|
+ (
|
|
|
+ array
|
|
|
+ (
|
|
|
+ array('审核时间', $operdate),
|
|
|
+ array('审核状态', $audit_name),
|
|
|
+ array('备注', $info['audit_desc']),
|
|
|
+ array('发放状态', $f_name),
|
|
|
+ array('备注', $info['fafang_desc']),
|
|
|
+ ),
|
|
|
+ array
|
|
|
+ (
|
|
|
+ array('支付凭证', $info['pic']),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ $button = array();
|
|
|
+ if($info['type'] == 2){
|
|
|
+ $purl = Dever::url('project/database/update?project=shop&table=record&where_id='.$info['id'].'&status=1&col=id,audit,audit_desc', 'manage');
|
|
|
+ if($info['audit'] == 1){
|
|
|
+ $button[] = array
|
|
|
+ (
|
|
|
+ 'type' => 'edit',
|
|
|
+ 'link' => $purl,
|
|
|
+ 'name' => '审核',
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if($info['audit'] == 2 && $info['fafang'] == 1){
|
|
|
+ $purl = Dever::url('project/database/update?project=shop&table=record&where_id='.$info['id'].'&status=1&col=id,fafang,fafang_desc,fpic', 'manage');
|
|
|
+ $button[] = array
|
|
|
+ (
|
|
|
+ 'type' => 'edit',
|
|
|
+ 'link' => $purl,
|
|
|
+ 'name' => '发放',
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $head = array
|
|
|
+ (
|
|
|
+ 'name' => '基本资料',
|
|
|
+ 'btn' => $button,
|
|
|
+ );
|
|
|
+ $foot = $button;
|
|
|
+ $html = Dever::show($head, $result, $foot);
|
|
|
+
|
|
|
+ return $html;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function search_api()
|
|
|
+ {
|
|
|
+ $value = Dever::input('value');
|
|
|
+ if(!$value){
|
|
|
+ return '店铺编号不正确';
|
|
|
+ }
|
|
|
+ if ($value) {
|
|
|
+ $data = Dever::db('shop/info')->one(array('sid' => $value,'state' =>1));
|
|
|
+ $table = array();
|
|
|
+ if ($data) {
|
|
|
+ $table = array();
|
|
|
+ $table['head'] = array('序列号', '门店编号','姓名', '手机号');
|
|
|
+ $table['body'] = array();
|
|
|
+ $table['body'] = array($data['id'], $data['sid'],$data['name'], $data['mobile']);
|
|
|
+
|
|
|
+ $result[] = array
|
|
|
+ (
|
|
|
+ 'type' => 'table',
|
|
|
+ 'content' => $table,
|
|
|
+ );
|
|
|
+
|
|
|
+ $html = Dever::show('', $result, false, false);
|
|
|
+ return $html;
|
|
|
+ }else{
|
|
|
+ return '店铺不存在';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function out_record($data){
|
|
|
+ $header = array('交易流水号','交易时间','门店名称','门店编号','门店手机号','交易类型','交易金额','交易后余额','交易状态','备注');
|
|
|
+ $body = array();
|
|
|
+ foreach($data as $k => $v){
|
|
|
+ $shop = Dever::db('shop/info')->find($v['shop_id']);
|
|
|
+ $typeconfig = Dever::db('shop/record')->config['config_type'];
|
|
|
+ $type = Dever::status($typeconfig,$v['type']);
|
|
|
+ $config = Dever::db('shop/record')->config['config_status'];
|
|
|
+ $status = Dever::status($config,$v['status']);
|
|
|
+ $d = array
|
|
|
+ (
|
|
|
+ $v['order_num'],
|
|
|
+ date('Y-m-d H:i',$v['cdate']),
|
|
|
+ $shop['name'],
|
|
|
+ $shop['sid'],
|
|
|
+ $shop['mobile'],
|
|
|
+ $type,
|
|
|
+ $v['price'],
|
|
|
+ $v['yue'],
|
|
|
+ $status,
|
|
|
+ $v['audit_desc'],
|
|
|
+ );
|
|
|
+ $body[] = $d;
|
|
|
+ }
|
|
|
+ $file = Dever::input('excel_name');
|
|
|
+ return Dever::excelExport($body, $header, $file);
|
|
|
+ }
|
|
|
+ public function getString($shop_id){
|
|
|
+ $info = Dever::db('shop/info')->find($shop_id);
|
|
|
+ return '门店信息:'.$info['name'].' '.$info['sid'].' '.$info['truename'].' '.$info['mobile'];
|
|
|
+ }
|
|
|
+
|
|
|
+}
|