dever 6 years ago
parent
commit
7c8a28e0c5

+ 11 - 0
code/database/config.php

@@ -48,6 +48,17 @@ return array
 			'value'		=> '',
 		),
 
+		'product_num'		=> array
+		(
+			'type' 		=> 'varchar-32',
+			'name' 		=> '兑换本数',
+			'default' 	=> '1',
+			'desc' 		=> '兑换本数',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'value'		=> '',
+		),
+
 		'cdate'		=> array
 		(
 			'type' 		=> 'int-11',

+ 12 - 0
code/database/info.php

@@ -58,6 +58,18 @@ return array
 			'list'		=> true,
 		),
 
+		'product_num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '兑换本数',
+            'default'   => '1',
+            'desc'      => '兑换本数',
+            'match'     => 'option',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
 		'type'		=> array
 		(
 			'type' 		=> 'int-11',

+ 4 - 2
code/lib/Manage.php

@@ -35,6 +35,7 @@ class Manage
 	public function create($id, $name, $param)
 	{
 		$code = Dever::param('num', $param);
+		$product_num = Dever::param('product_num', $param);
 		$product_id = Dever::param('product_id', $param);
 
 		//$total = Dever::db('code/info')->total(array('product_id' => $product_id, 'type' => 1));
@@ -43,12 +44,12 @@ class Manage
 			$num = $code - $total;
 
 			for ($i = 0; $i < $num; $i++) {
-				$this->createCode($product_id);
+				$this->createCode($product_id, $product_num);
 			}
 		}
 	}
 
-	private function createCode($product_id)
+	private function createCode($product_id, $product_num = 1)
 	{
 		$code = Dever::rand(8, 0);
 		$data['product_id'] = $product_id;
@@ -57,6 +58,7 @@ class Manage
 		if ($total > 0) {
 			return $this->createCode($product_id, $id);
 		}
+		$data['product_num'] = $product_num;
 		$data['type'] = 1;
 		Dever::db('code/info')->insert($data);
 		return $code;

+ 18 - 6
journal/database/buy_num.php

@@ -41,13 +41,25 @@ return array
             'value'     => Dever::input('search_option_info_id')
         ),
 
+        'num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '购买本数-直接填写购买的小刊本数数字即可',
+            'default'   => '1',
+            'desc'      => '购买本数',
+            'match'     => 'option',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
         'name'      => array
         (
             'type'      => 'varchar-80',
-            'name'      => '购买名称-一般为“购买n本”,如购买1本',
+            'name'      => '购买名称-一般为“购买n本”,如购买1本,如果为空,则根据购买本数自动生成如“购买n本”',
             'default'   => '',
             'desc'      => '购买名称',
-            'match'     => 'is_string',
+            'match'     => 'option',
             'update'    => 'text',
             'search'    => 'fulltext',
             'list'      => true,
@@ -56,10 +68,10 @@ return array
         'price'     => array
         (
             'type'      => 'varchar-50',
-            'name'      => '购买时的标价',
+            'name'      => '购买时的标价-为空则自动根据小刊的单本支付价格计算',
             'default'   => '',
             'desc'      => '购买时的标价',
-            'match'     => 'is_string',
+            'match'     => 'option',
             'update'    => 'text',
         ),
 
@@ -70,7 +82,7 @@ return array
             'default'   => '',
             'desc'      => '支付价格',
             'match'     => 'is_string',
-            'update'    => 'text',
+            //'update'    => 'text',
         ),
 
         'score'         => array
@@ -80,7 +92,7 @@ return array
             'default'   => '',
             'desc'      => '增加积分数',
             'match'     => 'is_string',
-            'update'    => 'text',
+            //'update'    => 'text',
         ),
 
         'reorder'       => array

+ 25 - 1
journal/database/info.php

@@ -301,7 +301,31 @@ return array
 			'match' 	=> 'option',
 			'update'	=> 'radio',
 			'option'	=> $buy,
-		),
+			'control'	=> 'buy',
+		),
+
+		'cash'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '单本支付价格-实际的小刊单本支付价格,单位元,直接填写数字即可',
+            'default'   => '',
+            'desc'      => '支付价格',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'show'		=> 'buy=1',
+        ),
+
+
+        'score'         => array
+        (
+            'type'      => 'varchar-80',
+            'name'      => '购买增加积分数-直接填写购买单本小刊的积分数,设置之后,积分规则里的设置将失效,如果设置为0,则按照积分规则进行增加积分',
+            'default'   => '20',
+            'desc'      => '增加积分数',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'show'		=> 'buy=1',
+        ),
 
 		'share_yes'		=> array
 		(

+ 7 - 3
journal/lib/Pay.php

@@ -33,14 +33,18 @@ class Pay
                 # 订阅
                 Dever::load('act/lib/subscribe')->submit($uid, $product_id, 1);
 
+                $score = false;
                 $num = false;
                 if ($order['buy_id'] > 0) {
+                    $info = Dever::db('journal/info')->one($order['product_id']);
                     $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
-                    if ($buy && $buy['score'] > 0) {
-                        $num = $buy['score'];
+                    if ($info && $buy && $info['score'] > 0) {
+                        $score = $buy['num'] * $info['score'];
+                    } elseif ($info && $buy) {
+                        $num = $buy['num'];
                     }
                 }
-                Dever::score($uid, 'buy_journal', '购买小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $product_id, $num);
+                Dever::score($uid, 'buy_journal', '购买小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $order['product_id'], $score, $num);
 
                 # 发消息
                 $journal = Dever::db('journal/info')->one($order['product_id']);

+ 42 - 2
main/src/Journal.php

@@ -194,9 +194,31 @@ class Journal extends Core
             $this->data['buy_desc'] = $buy['buy_content'];
         }
 
+        if ($this->data['info']['buy'] == 2) {
+            $this->data['buy_list'] = array();
+            return $this->data;
+        }
         # 获取购买列表
         $this->data['buy_list'] = Dever::db('journal/buy_num')->getAll(array('info_id' => $id));
 
+        if ($this->data['info']['cash'] <= 0) {
+            $this->data['info']['cash'] = 100000;
+        }
+        if ($this->data['buy_list']) {
+            foreach ($this->data['buy_list'] as $k => $v) {
+                if (!$v['name']) {
+                    $this->data['buy_list'][$k]['name'] = '购买' . $v['num'] . '本';
+                }
+
+                $price = $v['num'] * $this->data['info']['cash'];
+                if (!$v['price']) {
+                    $this->data['buy_list'][$k]['price'] = $price . '元';
+                }
+
+                $this->data['buy_list'][$k]['cash'] = $price;
+            }
+        }
+
         return $this->data;
     }
 
@@ -408,6 +430,10 @@ class Journal extends Core
             Dever::alert('请传入正确的小刊ID');
         }
 
+        if (!$buy['name']) {
+            $buy['name'] = '购买' . $buy['num'] . '本';
+        }
+
         $user = Dever::db('passport/user')->one($this->data['uid']);
         $wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid']));
 
@@ -431,8 +457,9 @@ class Journal extends Core
         $order_data['type'] = 1;
         $order_data['status'] = 1;
         $order_data['name'] = $info['name'] . '-' . $buy['name'];
-        $order_data['num'] = Dever::input('num', 1);
-        $order_data['cash'] = $buy['cash'] * $order_data['num'];
+        //$order_data['num'] = Dever::input('num', 1);
+        $order_data['num'] = $buy['num'];
+        $order_data['cash'] = $info['cash'] * $order_data['num'];
 
         $id = Dever::db('journal/order')->insert($order_data);
 
@@ -567,6 +594,19 @@ class Journal extends Core
             # 订阅
             Dever::load('act/lib/subscribe')->submit($this->data['uid'], $journal_id, 2);
 
+            $score = false;
+            $num = false;
+            if ($order['buy_id'] > 0 && isset($info['product_num']) && $info['product_num'] > 0) {
+                $journal_info = Dever::db('journal/info')->one($journal_id);
+                if ($journal_info && $journal_info['score'] > 0) {
+                    $score = $info['product_num'] * $info['score'];
+                } elseif ($journal_info) {
+                    $num = $info['product_num'];
+                }
+            }
+            # 增加积分
+            Dever::score($this->data['uid'], 'dh_journal', '兑换小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $journal_id, $score, $num);
+
         } else {
             Dever::alert('请输入正确的兑换码');
         }

+ 9 - 0
score/database/action_log.php

@@ -93,6 +93,15 @@ return array
 		),
 
 		'num'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '增加的积分将乘以该数量',
+			'default' 	=> '0',
+			'desc' 		=> '积分数',
+			'match' 	=> 'is_string',
+		),
+
+		'mscore'		=> array
 		(
 			'type' 		=> 'varchar-30',
 			'name' 		=> '手动增加积分数',

+ 11 - 3
score/lib/Core.php

@@ -11,7 +11,7 @@ class Core
 	 *
 	 * @return mixed
 	 */
-	public function log($uid, $action_key, $action_name, $callback = '', $score = false)
+	public function log($uid, $action_key, $action_name, $callback = '', $score = false, $num = false)
 	{
 		$action = Dever::db('score/action')->one(array('key' => $action_key));
 
@@ -26,7 +26,10 @@ class Core
 			$insert['action_id'] = $action['id'];
 			$insert['callback'] = $callback;
 			if ($score > 0) {
-				$insert['num'] = $score;
+				$insert['mscore'] = $score;
+			}
+			if ($num > 0) {
+				$insert['num'] = $num;
 			}
 			$log_id = Dever::db('score/action_log')->insert($insert);
 
@@ -51,8 +54,13 @@ class Core
 
 	private function rule($log, $info)
 	{
+		# 手动增加积分
+		if (isset($log['mscore']) && $log['mscore'] > 0) {
+			$info['num'] = $log['mscore'];
+		}
+		# 积分乘以倍数
 		if (isset($log['num']) && $log['num'] > 0) {
-			$info['num'] = $log['num'];
+			$info['num'] = $info['num'] * $log['num'];
 		}
 		if ($info['num'] == 0) {
 			return;