Explorar o código

add order_sended and order_received bonus

stanley-king %!s(int64=8) %!d(string=hai) anos
pai
achega
918c191d74

+ 11 - 3
core/framework/libraries/sms.php

@@ -16,6 +16,8 @@ class Sms
     const getbind_code = 4;
     const newcomer_code = 5;
     const newcomer_bonus_code = 6;
+    const order_sended = 7;
+    const order_received = 8;
 
     /*
      * 发送手机短信
@@ -73,9 +75,15 @@ class Sms
     private function mysend_yuntx($mobile, $content)
     {
         $type = intval($content['type']);
-        static $templates = array(self::register_code => '59006', self::resetpass_code => '63477',
-            self::getbonus_code => '63479', self::getbind_code => '59006',
-            self::newcomer_code => '92893',self::newcomer_bonus_code => '101581');
+        static $templates = array(self::register_code => '59006',
+            self::resetpass_code => '63477',
+            self::getbonus_code => '63479',
+            self::getbind_code => '59006',
+            self::newcomer_code => '92893',
+            self::newcomer_bonus_code => '101581',
+            self::order_sended => '146345',
+            self::order_received => '146346');
+
         if (!array_key_exists($type, $templates)) return -1;
 
         return $this->send_msg($mobile, $content['datas'], $templates[$type]);

+ 5 - 1
data/logic/order.logic.php

@@ -5,8 +5,11 @@
  * 好商城 V3 33hao.com
  */
 defined('InShopNC') or exit('Access Invalid!');
-class orderLogic {
 
+require_once(BASE_ROOT_PATH . '/helper/account_helper.php');
+
+class orderLogic
+{
     /**
      * 取消订单
      * @param array $order_info
@@ -111,6 +114,7 @@ class orderLogic {
             if (!$update) {
                 throw new Exception('保存失败');
             }
+            account_helper::onOrderSuccess($order_id);
 
             //添加订单日志
             $data = array();

+ 43 - 38
helper/account_helper.php

@@ -10,6 +10,7 @@
 require_once (BASE_ROOT_PATH . '/helper/bonus_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/push_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/sms_helper.php');
 
 class sys_bonus
 {
@@ -510,15 +511,14 @@ class account_helper
         $money = intval($order_amount/100) * 100;
 
         $rate_moneys = [];
-        if(intval($money / 2) > 0) {
-            $item['amount'] = intval($money / 2);
-            $item['num'] = 10;
+        if(intval($money / 4) > 0) {
+            $item['amount'] = intval($money / 4);
+            $item['num'] = 5;
             $item['rate'] = 40;
             $rate_moneys[] = $item;
         }
 
         if($money == 0) $money = 100;
-
         {
             $item['amount'] = $money;
             $item['num'] = 10;
@@ -528,6 +528,7 @@ class account_helper
 
         return $rate_moneys;
     }
+
     static public function paysuccess_bonus($buyer_id, $total_amount)
     {
         $rate_moneys = self::make_rates($total_amount);
@@ -544,7 +545,7 @@ class account_helper
             $param['send_start_date'] = time();
             $param['send_end_date'] = $param['send_start_date'] + self::period_hour * 3600;
             $param['make_type'] = bonus\type::MakePayType;
-            $param['type_name'] = "支付奖励红包";
+            $param['type_name'] = "支付奖励红包(可分享)";
 
             $ret = bonus_helper::make_bonus($param,array($rate_money));
 
@@ -552,14 +553,10 @@ class account_helper
                 $type_sn = $ret['type_sn'];
                 $bonus = bonus_helper::send($type_sn,array($buyer_id));
                 $val += $bonus[0]['bonus_value'];
-                Log::record("type_sn={$type_sn}  value={$val}");
             }
         }
 
-        push_helper::paysuccess_bonus($buyer_id,$val);
-        Model('member')->inc_rate_version($buyer_id);
-
-        return array('money' => $val,'total_num' => self::total_number,'sender_name' => '熊猫美妆');
+        return $val;
     }
 
     public static function onPredRefund($change_type,$member_id,$sn,$refund_id)
@@ -662,46 +659,54 @@ class account_helper
     }
 
     //在支付成功之后,可以提醒用户收到货后,可以收到红包奖励。
-    public static function onPaySuccess($member_id)
+    public static function onPaySuccess($pay_sn)
     {
-        Log::record("account_helper::onOrderSuccess {$member_id}",Log::DEBUG);
+        Log::record("account_helper::onOrderSuccess pay_sn={$pay_sn}",Log::DEBUG);
+        $mod = Model('order');
+        $info = $mod->getOrderInfo(array('pay_sn' => $pay_sn));
+        $buyer_id = intval($info['buyer_id']);
+        push_helper::paysuccess($buyer_id);
     }
 
     //在发货之后,可以提醒用户留意收货,在订单中查看物流,短信通知
-    public static function onOrderSend($member_id)
+    public static function onOrderSend($order_sn,$logistics_company,$logistics)
     {
-        Log::record("account_helper::onOrderSend {$member_id}",Log::DEBUG);
+        Log::record("account_helper::onOrderSend order_sn={$order_sn} company={$logistics_company} no={$logistics}",Log::DEBUG);
+        $mod = Model('order');
+        $info = $mod->getOrderInfo(array('order_sn' => $order_sn));
+        $buyer_id = intval($info['buyer_id']);
+        if($buyer_id <= 0) return;
 
+        $mem_info = new member_info($buyer_id);
+        $mobile = $mem_info->mobile();
+        sms_helper::send_nostore_message($mobile,Sms::order_sended,array('company'=> $logistics_company,'logistics'=>$logistics,'time'=>'5'));
     }
 
-
-    public static function onOrderSuccess($pay_sn)
+    public static function onOrderSuccess($order_id)
     {
-        $data = &$result['data'];
-        $order_amount = 0.0;
-        $goods_amount = 0.0;
-        if(is_array($data['order_list']))
-        {
-            foreach($data['order_list'] as $key => $order) {
-                $order_amount += doubleval($order['order_amount']);
-                $goods_amount += doubleval($order['goods_amount']);
-            }
+        if(empty($pay_sn)) {
+            Log::record("account_helper::onOrderSuccess $order_id error.",Log::ERR);
+        } else {
+            Log::record("account_helper::onOrderSuccess $order_id={$order_id}.",Log::ERR);
+        }
 
-            $mod = Model('order');
-            $info = $mod->getOrderInfo(array('pay_sn' => $pay_sn));
-            $buyer_id = intval($info['buyer_id']);
-            $goods_amount = intval($info['goods_amount']);
+        $mod_order = Model('order');
+        $order = $mod_order->getOrderInfo(array('order_id' => $order_id));
 
-            $ret = account_helper::paysuccess_bonus($buyer_id,$goods_amount);
-            if($ret == false) {
-                Log::record("向用户发送购物后分享红包失败",log::ERR);
-                return false;
-            } else {
-                return true;
-            }
+        $buyer_id = intval($order['buyer_id']);
+        $goods_amount = intval($order['goods_amount']);
+        if($buyer_id <= 0) {
+            Log::record("account_helper::onOrderSuccess err buyer_id.",Log::ERR);
+            return;
         }
-        else {
-            return false;
+
+        $bonus_amount = account_helper::paysuccess_bonus($buyer_id,$goods_amount);
+        if(intval($bonus_amount * 100) + 0.5 > 10)
+        {
+            push_helper::paysuccess_bonus($buyer_id,$bonus_amount);
+            $mem_info = new member_info($buyer_id);
+            $mobile = $mem_info->mobile();
+            sms_helper::send_nostore_message($mobile,Sms::order_received,array('time'=>'5'));
         }
     }
 }

+ 8 - 0
helper/push_helper.php

@@ -55,7 +55,15 @@ class push_helper
         $push_param['go_type']   = 'bonus';
         QueueClient::push('upushSendMsg',$push_param);
     }
+    public static function paysuccess($member_id)
+    {
+        $push_param = array();
+        $push_param['member_id'] = $member_id;
+        $push_param['text']      = "已收到你的货款,请留意发货短信,确认收货后会有红包奖励~";
+        $push_param['go_type']   = '';
 
+        QueueClient::push('upushSendMsg',$push_param);
+    }
     public static function paysuccess_bonus($member_id,$money)
     {
         $push_param = array();

+ 2 - 0
mobile/dispatch_notify.php

@@ -7,6 +7,7 @@
  */
 
 require_once(BASE_ROOT_PATH . '/helper/kdn_helper.php');
+require_once(BASE_ROOT_PATH . '/helper/account_helper.php');
 
 fcgi_header("Content-Type: text/plain; charset=UTF-8");
 try
@@ -34,6 +35,7 @@ try
     {
         if ($status == 1)
         {
+            account_helper::onOrderSend($order_sn,$logistics_company,$logistics_no);
             $order = Model('order');
             $ret = $order->setOrderDelivery($order_sn, $shipping_express_id, $logistics_no, $ship_time);
             if ($ret) {

+ 17 - 10
test/account_helperTest.php

@@ -88,16 +88,6 @@ class account_helperTest extends PHPUnit_Framework_TestCase
         $brands = brand_helper::instance()->brandex();
     }
 
-    public function testPaysuccess()
-    {
-        account_helper::paysuccess_bonus(38682,1000);
-
-        $mod = Model('order');
-        $info = $mod->getOrderInfo(array('pay_sn' => '740532913609644490'));
-        $buyer_id = intval($info['buyer_id']);
-        $goods_amount = intval($info['goods_amount']);
-    }
-
     public function testEvalu()
     {
         $data = [];
@@ -115,6 +105,23 @@ class account_helperTest extends PHPUnit_Framework_TestCase
         $y = json_decode($x,true);
     }
 
+    public function testPaysuccess()
+    {
+        $pay_sn = '910510761110261481';
+        account_helper::onPaySuccess($pay_sn);
+    }
+
+
+    public function testOrderSuccess()
+    {
+        $mod = Model('order');
+        $pay_sn = '910510761110261481';
+        $order_info = $mod->getOrderInfo(array('pay_sn' => $pay_sn));
+        $logic_order = Logic('order');
+        $result = $logic_order->changeOrderStateReceive($order_info,'system','系统','超期未收货系统自动完成订单');
+
+    }
+
 
     public function testUpfile()
     {

+ 10 - 0
test/queueTest.php

@@ -35,6 +35,16 @@ class queueTest extends PHPUnit_Framework_TestCase
         QueueClient::push('upushSendMsg',$param);
     }
 
+    public function testOrderSuccess()
+    {
+        $mod = Model('order');
+        $pay_sn = '910510761110261481';
+        $order_info = $mod->getOrderInfo(array('pay_sn' => $pay_sn));
+        $logic_order = Logic('order');
+        $result = $logic_order->changeOrderStateReceive($order_info,'system','系统','超期未收货系统自动完成订单');
+
+    }
+
     public static function tearDownAfterClass()
     {
     }