Forráskód Böngészése

增加生成多份红包接口

stanley-king 7 éve
szülő
commit
4578e8d01d

+ 37 - 10
admin/control/person_bonus.php

@@ -25,7 +25,7 @@ class activity_bonus
         $result = [];
         foreach ($params as $val)
         {
-            if(preg_match_all('/^(\d{1,3})\|(\d{1,6})\|(\d{1,4})$/', $val, $match))
+            if(preg_match_all('/^(\d{1,3})\|(\d{1,7})\|(\d{1,4})$/', $val, $match))
             {
                 $item['rate'] = intval($match[1][0]);
                 $item['amount'] = intval($match[2][0]);
@@ -247,15 +247,42 @@ class person_bonusControl extends SystemControl
     {
         if(chksubmit())
         {
-            $maker = new activity_bonus();
-            $ret = $maker->make($_POST);
-            if($ret == false) {
-                $err = $maker->err();
-                showMessage($err,'index.php?act=person_bonus&op=promotion','','error');
-            } else {
-                Tpl::output('type_sn',$ret['type_sn']);
-                Tpl::output('bonus_url',$ret['url']);
-                Tpl::showpage('person_bonus.activity');
+            $copies = intval($_POST['copies']);
+            if($copies <=0 ) {
+                showMessage("份数参数必须大于0",'index.php?act=person_bonus&op=promotion','','error');
+            }
+            else
+            {
+                if($copies == 1)
+                {
+                    $maker = new activity_bonus();
+                    $ret = $maker->make($_POST);
+                    if($ret == false) {
+                        $err = $maker->err();
+                        showMessage($err,'index.php?act=person_bonus&op=promotion','','error');
+                    } else {
+                        Tpl::output('type_sn',$ret['type_sn']);
+                        Tpl::output('bonus_url',$ret['url']);
+                        Tpl::showpage('person_bonus.activity');
+                    }
+                }
+                else
+                {
+                    $urls = [];
+                    for($i = 0; $i < $copies; ++$i)
+                    {
+                        $maker = new activity_bonus();
+                        $ret = $maker->make($_POST);
+                        if($ret != false) {
+                            $urls[] = $ret['url'];
+                        }
+                    }
+
+                    $bonus_url = implode(",",$urls);
+                    Tpl::output('type_sn',"xxxxx");
+                    Tpl::output('bonus_url',$bonus_url);
+                    Tpl::showpage('person_bonus.activity');
+                }
             }
         }
         else

+ 12 - 2
admin/templates/default/person_bonus.activity.php

@@ -77,6 +77,16 @@
                         <input type="text" placeholder="2017-03-02 10:00:00" name="end_time" class="txt">
                     </td>
                 </tr>
+                <tr class="noborder">
+                    <td class="vatop rowform">
+                        <label class="validation">红包份数:</label>
+                    </td>
+                </tr>
+                <tr class="noborder">
+                    <td class="vatop rowform">
+                        <input type="text" placeholder="1" name="copies" class="txt">
+                    </td>
+                </tr>
             </tbody>
 
             <tfoot>
@@ -87,8 +97,8 @@
             <?php
             if(!empty($output['type_sn']))
             {
-                echo '<tr><td><label class="validation">生成的红包序列号:'. $output['type_sn'] . '</label></td></tr>';
-                echo '<tr class="noborder"><td class="vatop rowform"><label class="validation">'.$output['bonus_url'] .'</label></td></tr>';
+                echo '<tr><td><label>生成的红包序列号:'. $output['type_sn'] . '</label></td></tr>';
+                echo '<tr class="noborder"><td class="vatop rowform"><label>'.$output['bonus_url'] .'</label></td></tr>';
                 
             }
             ?>

+ 18 - 0
helper/session_helper.php

@@ -279,4 +279,22 @@ class session_helper
             return $_SESSION['member_wxopenid'];
         }
     }
+
+    static public function unionid()
+    {
+        if(!empty($_SESSION['member_wxunionid'])) {
+            return $_SESSION['member_wxunionid'];
+        }
+
+        if(array_key_exists('wx_author',$_SESSION))
+        {
+            if(array_key_exists('handled',$_SESSION['wx_author']))
+            {
+                $user_info = $_SESSION['wx_author']['user_info'];
+                return $user_info['unionid'];
+            }
+        }
+
+        return false;
+    }
 }

+ 1 - 2
helper/statistics_helper.php

@@ -17,7 +17,6 @@ class statistics_helper
 
     const interval_time = 1800;
 
-
     public static function instance()
     {
         if(self::$stInstance == null) {
@@ -70,7 +69,7 @@ class statistics_helper
 
                 foreach ($data as $key => $value)
                 {
-                    if($key = 'count')
+                    if($key == 'count')
                     {
                         if(empty($oper['count'])) {
                             $oper['count'] = 0;

+ 1 - 1
mobile/control/index.php

@@ -82,7 +82,7 @@ class indexControl extends specialControl
             return;
         }
         else {
-            fcgi_header('location:http://p.lrlz.com/hfive/inoherb/index.html#wechat_redirect');
+            fcgi_header('location:http://p.lrlz.com/hfive/inoherb/index.html');
         }
     }
 

+ 232 - 0
mobile/control/inoherb.php

@@ -0,0 +1,232 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/6/9
+ * Time: 上午11:57
+ */
+
+class inoherbControl extends mobileControl
+{
+    private $mModInoherb;
+
+    public function __construct()
+    {
+        parent::__construct();
+        $this->mModInoherb = Model('inoherb');
+    }
+    public function listOp()
+    {
+        $items = $this->items($this->page_size(),false);
+        $count = $this->mModInoherb->gettotalpage();
+        if(empty($items)) {
+            return self::outsuccess(['articles' => null,
+                'mobile_page' => mobile_page(0)]);
+        } else {
+            $articles = $this->format($items);
+            return self::outsuccess(['articles' => $articles,
+                'mobile_page' => mobile_page($count)]);
+        }
+
+    }
+    public function addOp()
+    {
+        $flower_type = intval($_GET['flower_type']);
+        $content = $_GET['content'];
+        if(empty($content)) {
+            return self::outerr(errcode::ErrParamter,"填写的内容不能为空.");
+        }
+
+        $content = urldecode($content);
+        $trans = new trans_wapper($this->mModInoherb);
+        try
+        {
+            if(!$this->exists())
+            {
+                $data['content'] = $content;
+                $data['flower_type'] = $flower_type;
+                $data['unionid'] = session_helper::unionid();
+                $data['content'] = $content;
+                $data['likes'] = 0;
+
+                if(session_helper::logined()) {
+                    $data['member_id'] = session_helper::memberid();
+                } else {
+                    $data['member_id'] = 0;
+                }
+                $this->mModInoherb->insert($data);
+            }
+
+            $trans->commit();
+        } catch (Exception $ex) {
+            $trans->rollback();
+        }
+
+        return self::outsuccess(null);
+    }
+
+    public function supportOp()
+    {
+        $inoherb_id = intval($_GET['inoherb_id']);
+        if($inoherb_id < 0) {
+            return self::outerr(errcode::ErrParamter,'错误的文章序列号.');
+        }
+
+        if($this->supported($inoherb_id)) {
+            $supported = false;
+            $supports = $this->unsupport($inoherb_id);
+        } else {
+            $supported = true;
+            $supports = $this->support($inoherb_id);
+        }
+
+        return self::outsuccess(['likes' => $supports,'supported' => $supported,'inoherb_id' => $inoherb_id]);
+    }
+
+    private function supported($inoherb_id)
+    {
+        $time = strtotime(date('Y-m-d',time()));
+        if(!isset($_SESSION['inoherb'])) {
+            $_SESSION['inoherb'] = [];
+        }
+        if(!isset($_SESSION['inoherb'][$time])) {
+            $_SESSION['inoherb'][$time] = [];
+        }
+
+        $inoherb = &$_SESSION['inoherb'][$time];
+        if(algorithm::binary_search($inoherb,$inoherb_id)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function support($inoherb_id)
+    {
+        $time = strtotime(date('Y-m-d',time()));
+        if(!isset($_SESSION['inoherb'])) {
+            $_SESSION['inoherb'] = [];
+        }
+        if(!isset($_SESSION['inoherb'][$time])) {
+            $_SESSION['inoherb'][$time] = [];
+        }
+
+        $inoherb = &$_SESSION['inoherb'][$time];
+        if(algorithm::binary_search($inoherb,$inoherb_id) == false) {
+            $pos = algorithm::lower_bonud($inoherb,$inoherb_id);
+            algorithm::array_insert($inoherb,$pos,$inoherb_id);
+            $ret = $this->mModInoherb->where(['inoherb_id' => $inoherb_id])->update(['likes' => ['exp', 'likes + 1']]);
+        }
+        return $this->likes($inoherb_id);
+    }
+
+    private function unsupport($inoherb_id)
+    {
+        $time = strtotime(date('Y-m-d',time()));
+        if(!isset($_SESSION['inoherb'])) {
+            $_SESSION['inoherb'] = [];
+        }
+        if(!isset($_SESSION['inoherb'][$time])) {
+            $_SESSION['inoherb'][$time] = [];
+        }
+
+        $inoherb = &$_SESSION['inoherb'][$time];
+        if(algorithm::binary_search($inoherb,$inoherb_id) == true) {
+            $pos = algorithm::lower_bonud($inoherb,$inoherb_id);
+            algorithm::array_erase($inoherb,$pos);
+            $ret = $this->mModInoherb->where(['inoherb_id' => $inoherb_id])->update(['likes' => ['exp', 'likes - 1']]);
+        }
+
+        return $this->likes($inoherb_id);
+    }
+
+    public function mineOp()
+    {
+        $inoherb_id = intval($_GET['inoherb_id']);
+        if($inoherb_id < 0) {
+            return self::outerr(errcode::ErrParamter,'错误的文章序列号.');
+        }
+        $item = $this->item(['unionid' => session_helper::unionid()]);
+        if(empty($item)) {
+            return self::outsuccess(['articles' => null,
+                'mobile_page' => mobile_page(0)]);        }
+        else
+        {
+            $articles = $this->format($item);
+            return self::outsuccess(['articles' => $articles,
+                'mobile_page' => mobile_page(1)]);
+        }
+    }
+
+    public function infoOp()
+    {
+        $inoherb_id = intval($_GET['inoherb_id']);
+        if($inoherb_id < 0) {
+            return self::outerr(errcode::ErrParamter,'错误的文章序列号.');
+        }
+        $item = $this->item(['inoherb_id' => $inoherb_id]);
+
+        if(empty($item)) {
+            return self::outsuccess(['articles' => null,
+                'mobile_page' => mobile_page(0)]);        }
+        else
+        {
+            $articles = $this->format($item);
+            return self::outsuccess(['articles' => $articles,
+                'mobile_page' => mobile_page(1)]);
+        }
+    }
+
+    private function exists()
+    {
+        $unionid = session_helper::unionid();
+        if(empty($unionid)) return true;
+
+        $items = $this->mModInoherb->field('*')->where(['unionid' => $unionid])->select();
+        if(empty($items)) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    private function likes($inoherb_id)
+    {
+        $items = $this->mModInoherb->field('likes')->where(['inoherb_id' => $inoherb_id])->select();
+        if(empty($items)) {
+            return 0;
+        } else {
+            return intval($items[0]['likes']);
+        }
+    }
+
+    private function item($condition)
+    {
+        return $this->mModInoherb->field('*')->where($condition)->select();
+    }
+
+    private function items($page = 0,$lock = false)
+    {
+        return $this->mModInoherb->field('*')->order('likes desc')->page($page)->lock($lock)->select();
+    }
+
+    private function format($items)
+    {
+        $result = [];
+        foreach ($items as $item)
+        {
+            $val = [];
+            $val['inoherb_id'] = intval($item['inoherb_id']);
+            $val['avatar'] = session_helper::avatar();
+            $val['flower_type'] = intval($item['flower_type']);
+            $val['content'] = $item['content'];
+            $val['likes'] = $item['likes'];
+            $val['supported'] = $this->supported($val['inoherb_id']);
+
+            $result[] = $val;
+        }
+
+        return $result;
+    }
+}

+ 1 - 1
mobile/control/login.php

@@ -27,7 +27,7 @@ class loginControl extends mobileHomeControl
 
     //客户登录身份类型
     protected $client_login_type_array = array(0, 1, 2);
-    private static $fields = 'member_id,member_mobile,member_wxopenid,member_name,member_truename,member_signname,' .
+    private static $fields = 'member_id,member_mobile,member_wxunionid,member_wxopenid,member_name,member_truename,member_signname,' .
     'member_nickname,member_avatar,member_sex,member_birthday,member_passwd,member_paypwd,member_email,member_mobile_bind,member_state';
 
     public function __construct()

+ 12 - 0
test/TestGD.php

@@ -0,0 +1,12 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/6/9
+ * Time: 下午5:25
+ */
+class TestGD extends PHPUnit_Framework_TestCase
+{
+
+}