dever 3 tahun lalu
induk
melakukan
39ab1e0500

+ 73 - 13
service/option/database/agreement.php

@@ -1,19 +1,28 @@
 <?php
 
-/*
 $status = array
 (
     1 => '待签署',
     2 => '有效',
     3 => '作废',
 );
-*/
-$status = array
+$audit = array
 (
-    1 => '有效',
-    2 => '有效',
-    3 => '作废',
+    1 => '未提交审核',
+    2 => '待审核',
+    3 => '审核通过',
+    4 => '审核未通过',
+);
+
+$audit_manage = array
+(
+    //1 => '未提交审核',
+    //2 => '待审核',
+    3 => '审核通过',
+    4 => '审核未通过',
 );
+$col = Dever::input('col');
+
 $aid = Dever::input('search_option_aid');
 $button = array();
 if ($aid) {
@@ -35,6 +44,10 @@ return array
     'lang' => '期权合同管理',
     'order' => 10,
     'status' => $status,
+    'end' => array
+    (
+        'update' => 'option/lib/manage.setAgreement_commit',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -101,13 +114,12 @@ return array
             'list_order' => 6,
         ),
 
-        'jiaofu_id'      => array
+        'jiaofu_date'      => array
         (
-            'type'      => 'varchar-100',
-            'name'      => '交付的id',
-            'default'   => '',
-            'desc'      => '交付的id',
-            'match'     => 'is_string',
+            'type'      => 'int-11',
+            'name'      => '交付时间',
+            'match'     => 'is_numeric',
+            'desc'      => '交付时间',
         ),
 
         'jiaofu_total'      => array
@@ -255,8 +267,55 @@ return array
             'match'     => 'is_numeric',
             'option'    => $status,
             'search'    => 'select',
+            //'list'      => true,
+            //'list_order' => 8,
+        ),
+
+        'audit'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '审核',
+            'default'   => $col ? '3' : '1',
+            'desc'      => '审核',
+            'match'     => 'is_numeric',
+            'option'    => $col ? $audit_manage : $audit,
+            'update'    => 'radio',
+            'control'   => 'audit',
+            'value'     => $col ? '3' : '1',
             'list'      => true,
-            'list_order' => 8,
+            'list_order' => 7,
+        ),
+
+        'audit_desc'        => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '审核备注',
+            'default'   => '',
+            'desc'      => '备注',
+            'match'     => 'option',
+            'update'    => 'textarea',
+            'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
+            'list_order'  => 9,
+        ),
+
+        'audit_date'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '审核时间',
+            'match'     => 'is_numeric',
+            'desc'      => '审核时间',
+            'default'   => '',
+        ),
+
+        'audit_admin'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '操作人',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '操作人',
+            'list'      => '"{audit_admin}" > 0 ? Dever::load("manage/admin-find#name", {audit_admin}) : "-"',
+            'list_order'  => 6,
         ),
 
         'state'     => array
@@ -293,6 +352,7 @@ return array
             'new' => array('查看', '"lib/agreement.location?id={id}"', 'option'),
             'oper' => array('作废并生成', '"option/lib/manage.dropAgreement?id={id}"', "{status} == 2"),
             'oper1' => array('更新', '"option/lib/manage.upAgreement?id={id}"', "{status} == 2"),
+            'edit' => array('审核', 'audit,audit_desc', '{audit} == 2'),
         ),
     ),
 

+ 43 - 14
service/option/database/bill_jiaofu.php

@@ -10,18 +10,14 @@ $status = array
 
 $audit = array
 (
-    1 => '未提交审核',
-    2 => '待审核',
-    3 => '审核通过',
-    4 => '审核未通过',
+    1 => '正常',
+    2 => '作废',
 );
 
 $audit_manage = array
 (
-    //1 => '未提交审核',
-    //2 => '待审核',
-    3 => '审核通过',
-    4 => '审核未通过',
+    //1 => '正常',
+    2 => '作废',
 );
 
 $col = Dever::input('col');
@@ -50,7 +46,7 @@ return array
     'order' => 90,
     'end' => array
     (
-        'update' => 'option/lib/manage.setJiaofu',
+        //'update' => 'option/lib/manage.setJiaofu',
     ),
     'config_audit' => $audit,
     # 数据结构
@@ -162,7 +158,7 @@ return array
             'update'    => 'radio',
             'control'   => 'audit',
             'value'     => $col ? '3' : '1',
-            'list'      => true,
+            //'list'      => true,
             'list_order' => 7,
         ),
 
@@ -174,7 +170,7 @@ return array
             'desc'      => '备注',
             'match'     => 'option',
             'update'    => 'textarea',
-            'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
+            //'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
             'list_order'  => 9,
         ),
 
@@ -194,8 +190,8 @@ return array
             'default'   => '',
             'match'     => 'is_numeric',
             'desc'      => '操作人',
-            'list'      => '"{audit_admin}" > 0 ? Dever::load("manage/admin-find#name", {audit_admin}) : "-"',
-            'list_order'  => 6,
+            //'list'      => '"{audit_admin}" > 0 ? Dever::load("manage/admin-find#name", {audit_admin}) : "-"',
+            //'list_order'  => 6,
         ),
 
         'desc'        => array
@@ -252,7 +248,7 @@ return array
         (
             //'list' => array('查看详情', '"member_area&mid={id}&page_type=1"'),
 
-            'edit' => array('审核', 'audit,audit_desc', '{audit} == 2'),
+            //'edit' => array('审核', 'audit,audit_desc', '{audit} == 2'),
             //'delete' => array('删除', '', '{status} == 1'),
         ),
     ),
@@ -275,5 +271,38 @@ return array
             'type' => 'all',
             'col' => '*',
         ),
+
+        'getTotal' => array
+        (
+            # 匹配的正则或函数 选填项
+            'where' => array
+            (
+                'aid' => 'yes',
+                'type' => 'yes',
+                'end' => array('yes-cdate', '<='),
+                'status' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => 'sum(cash) as total',
+        ),
+
+        'upYes' => array
+        (
+            # 匹配的正则或函数 选填项
+            'where' => array
+            (
+                'aid' => 'yes',
+                'end' => array('yes-cdate', '<='),
+                'status' => 'yes',
+                'state' => 1,
+            ),
+            'set' => array
+            (
+                'status' => 'yes',
+                'qdate' => 'yes',
+            ),
+            'type' => 'update',
+        ),
     ),
 );

+ 9 - 0
service/option/database/cash.php

@@ -60,6 +60,14 @@ return array
             'list_order' => 4,
         ),
 
+        'daijiaofu_date'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '最新的交付时间',
+            'match'     => 'is_numeric',
+            'desc'      => '最新的交付时间',
+        ),
+
         'daijiaofu'      => array
         (
             'type'      => 'float-11,2',
@@ -147,6 +155,7 @@ return array
             'set' => array
             (
                 'cash' => array('yes-daijiaofu', '+='),
+                'daijiaofu_date' => 'yes',
             ),
         ),
 

+ 11 - 11
service/option/lib/Agreement.php

@@ -56,8 +56,8 @@ class Agreement
             Dever::alert('您没有权限查看');
         }
 
-        if (isset($p['ids'])) {
-            $info['jiaofu_id'] = $p['ids'];
+        if (isset($p['date'])) {
+            $info['jiaofu_date'] = $p['date'];
         }
         if (isset($p['total'])) {
             $info['jiaofu_total'] = $p['total'];
@@ -79,7 +79,7 @@ class Agreement
     }
 
     # 合同名称
-    public function name($agreement, $info, $status = -1, $source = 1, $ids = false, $total = false)
+    public function name($agreement, $info, $status = -1, $source = 1, $date = false, $total = false)
     {
         if (!$agreement) {
             $agreement = Dever::db('setting/agreement')->find(array('type' => 6));
@@ -109,8 +109,8 @@ class Agreement
             $param['status'] = $status;
             $param['id'] = $info['id'];
             $param['agreement_id'] = $agreement['id'];
-            if ($ids) {
-                $param['ids'] = $ids;
+            if ($date) {
+                $param['date'] = $date;
             }
             if ($total) {
                 $param['total'] = $total;
@@ -130,7 +130,7 @@ class Agreement
     }
 
     # 新建合同
-    public function up($account, $ids, $total, $status = 1)
+    public function up($account, $date, $total, $status = 1)
     {
         $agreement = Dever::db('setting/agreement')->find(array('type' => 6));
         if (!$agreement) {
@@ -158,8 +158,10 @@ class Agreement
         $where['qdate'] = $qdate;
         $where['sdate'] = $sdate;
         $where['edate'] = $edate;
+        $where['status'] = 1;
+        $where['audit'] = 2;
 
-        $where['jiaofu_id'] = $ids;
+        $where['jiaofu_date'] = $date;
         $where['jiaofu_total'] = $total;
 
         $method = 'content_' . $agreement['type'];
@@ -410,10 +412,8 @@ class Agreement
     {
         $base = Dever::db('setting/base')->find();
 
-        if (isset($info['jiaofu_id'])) {
-            $jiaofu_id = explode(',', $info['jiaofu_id']);
-            $jiaofu = Dever::db('option/bill_jiaofu')->find($jiaofu_id[0]);
-            $info['jiaofu_date'] = date("Y年m月d日", $jiaofu['cdate']);
+        if (isset($info['jiaofu_date'])) {
+            $info['jiaofu_date'] = date("Y年m月d日", $info['jiaofu_date']);
         } else {
             $info['jiaofu_total'] = '0.00';
             $info['jiaofu_date'] = date("Y年m月d日");

+ 41 - 1
service/option/lib/Cash.php

@@ -112,6 +112,8 @@ class Cash
                         if ($data['status'] == 2) {
                             $update['fafang'] = 0;
                         }
+                    } else {
+                        $udpate['daijiaofu_date'] = time();
                     }
                     Dever::db('option/cash')->$method($update);
                 }
@@ -199,7 +201,8 @@ class Cash
         return $data;
     }
 
-    # 确认期权价值
+    # 确认期权价值 废弃
+    /*
     public function setValue_commit($info)
     {
         $cash = array();
@@ -230,6 +233,43 @@ class Cash
             }
         }
     }
+    */
+
+    # 确认期权价值
+    public function setValue($info)
+    {
+        $state = Dever::db('option/bill_jiaofu')->upYes(array('where_start' => $info['jiaofu_date'], 'where_aid' => $info['aid'], 'where_status' => 2, 'set_status' => 1, 'set_qdate' => time()));
+
+        if ($state) {
+            $account_cash = Dever::db('option/cash')->select(array('aid' => $info['aid']));
+            if ($account_cash) {
+                foreach ($account_cash as $k => $v) {
+                    $cash = Dever::db('option/bill_jiaofu')->getTotal(array('where_start' => $info['jiaofu_date'], 'where_type' => $v['type'], 'where_aid' => $info['aid'], 'where_status' => 2));
+                    if ($cash) {
+                        $update['where_id'] = $v['id'];
+                        $update['daijiaofu'] = $v['daijiaofu'] - $cash['total'];
+                        $update['jiaofu'] = $v['jiaofu'] + $cash['total'];
+                        if ($update['daijiaofu'] < 0) {
+                            $update['daijiaofu'] = 0;
+                        }
+                        $update['clear'] = true;
+                        Dever::db('option/cash')->update($update);
+
+                        # 获取待发放数据 对之前发放的数据进行发放
+                        $fafang = Dever::db('option/bill_fafang')->find(array('status' => 2, 'type' => $info['type'], 'aid' => $info['aid']));
+                        if ($fafang) {
+                            foreach ($fafang as $v1) {
+                                if ($cash['total'] >= $v1['cash']) {
+                                    Dever::db('option/bill_fafang')->update(array('where_id' => $v['id'], 'status' => 1));
+                                    $cash['total'] -= $v1['cash'];
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
 
     # 展示详情
     public function show()

+ 45 - 1
service/option/lib/Import.php

@@ -8,13 +8,13 @@ include('/share/lib/php/dever_package/excel/src/PHPExcel.php');
 
 class Import
 {
+    # 导入账户
     public function get_api()
     {
         $file = Dever::data() . 'qiquan.xlsx';
 
         $data = Dever::excelImport($file, 1, 5, 'excel');
 
-        # 主账户表
         if ($data) {
             foreach ($data as $k => $v) {
                 $state = preg_match(Dever::rule('mobile'), $v['C']);
@@ -39,4 +39,48 @@ class Import
         }
         return 'ok';
     }
+
+    # 导入交付记录
+    public function get_jiaofu_api()
+    {
+        $file = Dever::data() . 'qiquan.xlsx';
+
+        $data = Dever::excelImport($file, 2, 5, 'excel');
+
+        if ($data) {
+            $update = array();
+            foreach ($data as $k => $v) {
+                $state = preg_match(Dever::rule('mobile'), $v['A']);
+                if ($state) {
+                    $where['mobile'] = $v['A'];
+                    $type_name = $v['D'];
+                    if ($type_name == '期权') {
+                        $type = 1;
+                    } else {
+                        $type = 2;
+                    }
+                    $info = Dever::db('option/account')->find($where);
+                    if ($info && $info['status'] < 3) {
+                        $info = Dever::db('option/account')->find(array('key' => $info['key'], 'type' => 2));
+                        if ($info && $info['status'] < 3) {
+                            if (!isset($update[$info['id']][$type])) {
+                                $update[$info['id']][$type] = array();
+                                $update[$info['id']][$type]['total'] = 0;
+                                $update[$info['id']][$type]['desc'] = array();
+                            }
+                            $update[$info['id']][$type]['total'] += $v['C'];
+                            if ($v['E']) {
+                                $update[$info['id']][$type]['desc'][] = $v['E'];
+                            }
+                        }
+                    }   
+                }
+            }
+
+            if ($update) {
+
+            }
+        }
+        return 'ok';
+    }
 }

+ 24 - 0
service/option/lib/Manage.php

@@ -19,6 +19,30 @@ class Manage
         }
     }
 
+    # 协议审核
+    public function setAgreement_commit($id, $name, $data)
+    {
+        Dever::config('base')->hook = true;
+        $update = array();
+        $audit = Dever::param('audit', $data);
+        $info = Dever::db('option/agreement')->one($id);
+        if ($audit > 1 && $info) {
+            $admin = Dever::load('manage/auth.info');
+            $update['audit_date'] = time();
+            $update['audit_admin'] = $admin['id'];
+            if ($audit == 3) {
+                $update['status'] = 2;
+            }
+            
+            $update['where_id'] = $info['id'];
+            $state = Dever::db('option/agreement')->update($update);
+            if ($state && $audit == 3) {
+                Dever::load('option/lib/cash.setValue', $info);
+            }
+        }
+    }
+
+    # 交付审核 已废弃
     public function setJiaofu($id, $name, $data)
     {
         Dever::config('base')->hook = true;

+ 25 - 24
service/option/src/My.php

@@ -55,35 +55,35 @@ class My extends Core
     # 待交付期权列表
     public function getValue()
     {
-        $this->data['list'] = Dever::load('option/lib/cash')->getList($this->uid, 'jiaofu', 2, '待交付');
+        $this->data['list'] = Dever::db('option/cash')->select(array('aid' => $this->uid));
+
+        $agreement = Dever::db('option/agreement')->getOne(array('aid' => $this->uid));
 
         $audit = array
         (
             'status' => 1,
             'desc' => '',
         );
-        $ids = array();
+
+        if ($agreement) {
+            $audit['status'] = $agreement['audit'];
+            $audit['desc'] = $agreement['audit_desc'];
+        }
+
+        $date = 0;
         $total = 0;
+
         if ($this->data['list']) {
             foreach ($this->data['list'] as $k => $v) {
-                $ids[] = $v['id'];
-                $total += $v['cash'];
-                if ($v['audit'] == 4) {
-                    $audit['status'] = 4;
-                    $audit['desc'] = $v['audit_desc'];
-                    break;
-                } elseif ($v['audit'] == 2) {
-                    $audit['status'] = 2;
-                    break;
-                }
+                $date = $v['daijiaofu_date'];
+                $total += $v['daijiaofu'];
             }
         }
         $total = number_format($total, 2, '.', '');
-        $ids = implode(',', $ids);
 
         $this->data['audit'] = $audit;
 
-        $name = Dever::load('option/lib/agreement')->name(false, $this->user, 1, 2, $ids, $total);
+        $name = Dever::load('option/lib/agreement')->name(false, $this->user, 1, 2, $date, $total);
         $this->data['agreement_link'] = $name[1];
 
         return $this->data;
@@ -200,25 +200,26 @@ class My extends Core
             Dever::alert('请上传签名');
         }
 
+        $data = Dever::db('option/cash')->select(array('aid' => $this->uid));
+
         $data = Dever::load('option/lib/cash')->getList($this->uid, 'jiaofu', 2, '待交付');
         if (!$data) {
             Dever::alert('没有待交付的期权价值');
         }
-        $ids = array();
+
+        $date = 0;
         $total = 0;
-        foreach ($data as $k => $v) {
-            $ids[] = $v['id'];
-            $total += $v['cash'];
-            $update['where_id'] = $v['id'];
-            $update['audit'] = 2;
-            $update['qdate'] = time();
-            Dever::db('option/bill_jiaofu')->update($update);
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $date = $v['daijiaofu_date'];
+                $total += $v['daijiaofu'];
+            }
         }
-        $ids = implode(',', $ids);
+        $total = number_format($total, 2, '.', '');
 
         # 签署合同
         $this->user['sign'] = $update['sign'];
-        $agreement_id = Dever::load('option/lib/agreement')->up($this->user, $ids, $total);
+        $agreement_id = Dever::load('option/lib/agreement')->up($this->user, $date, $total);
 
         return $this->user;
     }