Example #1
0
 public function exec($params = null)
 {
     $special_remind_mdl = app::get('starbuy')->model('special_remind');
     $special = $special_remind_mdl->getList("*", array('remind_time|sthan' => time()));
     if ($special) {
         foreach ($special as $key => $val) {
             if ($val['member_id' == 0] && $val['remind_way'] == "msgbox") {
                 continue;
             }
             if ($val['remind_way'] == "email" || $val['remind_way'] == "msgbox") {
                 $val['goodsurl'] = app::get('site')->router()->gen_url(array('app' => 'starbuy', 'ctl' => 'site_team', 'act' => 'index', 'arg0' => $val['product_id'], 'full' => true));
             }
             $sdf[$val['remind_way']][] = $val;
         }
         foreach ($sdf as $key => $value) {
             if ($key == "email") {
                 $class = "starbuy_tasks_sendemail";
                 system_queue::instance()->publish($class, $class, $value);
             } elseif ($key == "sms") {
                 $class = "starbuy_tasks_sendsms";
                 system_queue::instance()->publish($class, $class, $value);
             } elseif ($key == "msgbox") {
                 $class = "starbuy_tasks_sendmsg";
                 system_queue::instance()->publish($class, $class, $value);
             }
             app::get('starbuy')->model('special_remind')->delete($value);
         }
     }
 }
Example #2
0
 public function create_import()
 {
     #检查导入文件是否合法
     $this->check_import_file();
     #将导入文件上传到服务器
     $data = $this->push_file($_POST);
     $queue_params = array('model' => $_POST['mdl'], 'filetype' => $data['filetype'], 'policy' => $this->queue_policy(), 'key' => $data['key']);
     system_queue::instance()->publish('importexport_tasks_runimport', 'importexport_tasks_runimport', $queue_params);
     app::get('importexport')->model('task')->create_task('import', $data);
     $echoMsg = app::get('importexport')->_('上传成功,已加入队列');
     $this->import_message(true, $echoMsg);
     #kernel::single('importexport_tasks_runimport')->exec($queue_params);
 }
Example #3
0
 public function create_export()
 {
     $filter = unserialize($_POST['filter']);
     $params = unserialize($_POST['params']);
     if (isset($filter['isSelectedAll']) && $filter['isSelectedAll'] == '_ALL_') {
         $filter = $this->view_filter($filter, $params);
     }
     $_POST['key'] = $this->gen_key();
     $queue_params = array('filter' => $filter, 'app_id' => $params['app'], 'model' => $params['mdl'], 'filetype' => $_POST['filetype'], 'policy' => $this->queue_policy(), 'key' => $_POST['key']);
     system_queue::instance()->publish('importexport_tasks_runexport', 'importexport_tasks_runexport', $queue_params);
     app::get('importexport')->model('task')->create_task('export', $_POST);
     //测试,直接导出数据到存储服务器,不进行队列
     #kernel::single('importexport_tasks_runexport')->exec($queue_params);
 }
Example #4
0
 public function create_export()
 {
     $filter = unserialize($_POST['filter']);
     $params = unserialize($_POST['params']);
     $_POST['key'] = $this->gen_key();
     $queue_params = array('filter' => $filter, 'app_id' => $params['app'], 'model' => $params['mdl'], 'filetype' => $_POST['filetype'], 'policy' => $this->queue_policy(), 'key' => $_POST['key']);
     $this->begin();
     if (system_queue::instance()->publish('importexport_tasks_runexport', 'importexport_tasks_runexport', $queue_params) && app::get('importexport')->model('task')->create_task('export', $_POST)) {
         $this->end(true, '创建导出任务成功!');
     } else {
         $this->end(false, '创建导入任务失败!');
     }
     //测试,直接导出数据到存储服务器,不进行队列
     #print_r($queue_params);exit;
     #vmc::singleton('importexport_tasks_runexport')->exec($queue_params);
 }
Example #5
0
 public static function trigger_all()
 {
     $cronentries = self::__get_enabled_cronentries();
     ignore_user_abort(1);
     $now = time();
     $filter = array();
     foreach ($cronentries as $cron) {
         //            var_dump(base_crontab_parser::parse($cron['schedule'], $cron['last']));
         if ($now >= base_crontab_parser::parse($cron['schedule'], $cron['last'])) {
             //todo: base_queue::instance()->addTask()
             //todo: update 变更为一次性更新
             $worker = $cron['id'];
             system_queue::instance()->publish('crontab:' . $worker, $worker);
             $filter['id'][] = $cron['id'];
             self::__log($cron['id'], $now, 'add queue ok');
         }
     }
     if (!empty($filter)) {
         app::get('base')->model('crontab')->update(array('last' => $now), $filter);
     }
 }
Example #6
0
 /**
  * 多进程执行队列
  *
  * @param string $queue_name
  * @param int $max
  * @param string $phpExec
  */
 public function exec($queue_name, $max, $phpExec = '')
 {
     $max = $max ? $max : 1;
     $time = time();
     while (1) {
         //执行死循环
         try {
             while ($this->threadRunning < $max && !system_queue::instance()->is_end($queue_name)) {
                 $this->running[] = new system_queue_consumer_proc_thread($queue_name, $phpExec);
                 usleep(200000);
                 $this->threadRunning++;
             }
         } catch (Exception $e) {
             switch ($e->getCode()) {
                 case 30001:
                     logger::emerg(sprintf('ERROR:%d @ %s', $e->getCode(), $e->getMessage));
                     exit;
             }
         }
         //检查是否已经结束
         if ($this->threadRunning == 0) {
             break;
         }
         //等待代码执行完成
         usleep(50000);
         $thread_close = array();
         //记录线程的关闭状态
         //检查已经完成的任务
         foreach ($this->running as $idx => $thread) {
             if (!$thread->isRunning() || $thread->isOverExecuted($max)) {
                 $thread_close[] = proc_close($thread->resource);
                 //记录线程的关闭状态
                 unset($this->running[$idx]);
                 $this->threadRunning--;
             }
         }
     }
 }
Example #7
0
 public function setUp()
 {
     $this->obj_queue = system_queue::instance();
 }
Example #8
0
 function import(&$contents, $app, $mdl)
 {
     $model = $this->model;
     if (!is_array($contents)) {
         $this->str2Array($contents);
     }
     if (!$this->data['title']) {
         $this->data = array('title' => array(), 'contents' => array());
     }
     $msg = array();
     while (true) {
         //
     }
     return array('success', $msg);
     while (true) {
         $row = current($contents);
         if (!is_array($row)) {
             $this->str2Array($row, ',');
         }
         if ($row) {
             foreach ($row as $num => $col) {
                 $row[$num] = trim($col, '"');
             }
         }
         $newObjFlag = false;
         $rowData = $model->prepared_import_csv_row($row, $this->data['title'], $tmpl, $mark, $newObjFlag, $msg);
         if ($rowData === false) {
             return array('failure', $msg);
         }
         if (!current($contents) || $newObjFlag) {
             if ($mark != 'title') {
                 $saveData = $model->prepared_import_csv_obj($this->data, $mark, $tmpl, $msg);
                 if ($saveData === false) {
                     return array('failure', $msg);
                 }
                 if ($saveData) {
                     $params = array('sdfdata' => $saveData, 'app' => $app, 'mdl' => $mdl);
                     system_queue::instance()->publish('desktop_tasks_runimport', 'desktop_tasks_runimport', $params);
                 }
                 if ($mark) {
                     eval('$this->data["' . implode('"]["', explode('/', $mark)) . '"] = array();');
                 }
             }
         }
         next($contents);
         if ($mark) {
             if ($mark == 'title') {
                 eval('$this->data["' . implode('"]["', explode('/', $mark)) . '"] = $rowData;');
             } else {
                 eval('$this->data["' . implode('"]["', explode('/', $mark)) . '"][] = $rowData;');
             }
         }
         if (!$row) {
             break;
         }
     }
     return array('success', $msg);
 }
Example #9
0
 private static function _send($type, $tmpl, $content, $sendType, $isqueue)
 {
     if ($isqueue) {
         $mess = config::get('messenger.messenger');
         $method = $mess[$type]['class'];
         $tmpl_name = 'messenger:' . $method . '/' . $tmpl;
         $queue_content = array('sendMethod' => $type, 'tmpl_name' => $tmpl_name, 'data' => $content, 'type' => $tmpl, 'sendType' => $sendType ? $sendType : 'notice');
         return system_queue::instance()->publish('system_tasks_sendmessenger', 'system_tasks_sendmessenger', $queue_content);
     } else {
         $result = self::sendMessenger($type, $tmpl, $content);
         if ($result['rsp'] == "succ") {
             return true;
         } elseif ($result['rsp'] == "fail") {
             return false;
         }
     }
 }
Example #10
0
 private function __order_payment($rel_id, &$sdf, &$status = 'succ', &$msg = '')
 {
     $objMath = kernel::single('ectools_math');
     $obj_orders = $this->app->model('orders');
     $subsdf = array('order_objects' => array('*', array('order_items' => array('*', array(':products' => '*')))));
     $sdf_order = $obj_orders->dump($rel_id, '*', $subsdf);
     $order_items = array();
     if ($sdf_order) {
         if ($sdf_order['member_id']) {
             $obj_members = $this->app->model('members');
             $arr_members = $obj_members->dump($sdf_order['member_id'], '*', array(':account@pam' => array('*')));
             $this->str_op_id = $sdf_order['member_id'];
             $this->str_op_name = $arr_members['pam_account']['login_name'];
         } else {
             $this->str_op_id = '0';
             $this->str_op_name = '';
         }
         if ($sdf_order['pay_status'] == '1') {
             $msg = app::get('b2c')->_('该订单已经支付,无需重新支付!');
             $status = 'failed';
             return false;
         }
         // Order information update.
         if ($objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])) < $sdf_order['cur_amount'] && $status != 'failed') {
             $pay_status = '3';
         } else {
             if ($status == 'succ' || $status == 'progress') {
                 if ($status == 'succ') {
                     $pay_status = '1';
                 } else {
                     $pay_status = '2';
                 }
             } else {
                 if ($objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])) > $sdf_order['cur_amount']) {
                     $msg = app::get('b2c')->_('支付金额超过需要支付的总金额!');
                     $status = 'failed';
                     return false;
                 }
                 $pay_status = '0';
             }
         }
         if ($sdf['status'] != 'progress' && $objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])) > $sdf_order['cur_amount']) {
             $msg = app::get('b2c')->_('支付金额超过需要支付的总金额,不能支付!');
             $status = 'failed';
             return false;
         }
         $arrOrder = array('order_id' => $rel_id, 'payment' => $sdf['pay_app_id'], 'payed' => $objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])) > $sdf_order['cur_amount'] ? $sdf_order['cur_amount'] : $objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])), 'pay_status' => $pay_status);
         // 支付完了,预存款
         if ($sdf['pay_app_id'] == 'deposit') {
             $objAdvance = $this->app->model("member_advance");
             $is_frontend = $this->from == 'Back' ? false : true;
             $status = $objAdvance->deduct($sdf_order['member_id'], $sdf['money'], app::get('b2c')->_('预存款支付订单'), $msg, $sdf['payment_id'], $rel_id, 'deposit', $sdf_order['memo'], $is_frontend);
             $error_Msg = $msg;
             if (!$status) {
                 return false;
             }
         } else {
             $error_Msg = $status == 'succ' || $status === true ? app::get('b2c')->_("订单号:") . $rel_id . ' ' . $arrPayments['app_name'] . app::get('b2c')->_("支付交易号: ") . $sdf['trade_no'] . app::get('b2c')->_(",交易成功!") : app::get('b2c')->_("订单号:") . $rel_id . ' ' . $arrPayments['app_name'] . app::get('b2c')->_("支付交易失败!");
         }
         $is_save = $obj_orders->update($arrOrder, array('order_id' => $rel_id));
         if (!$is_save) {
             $msg = app::get('b2c')->_('订单支付状态保存失败!');
             return false;
         }
         if (!$obj_orders->db->affect_row()) {
             $msg = app::get('b2c')->_('订单重复支付!');
             return false;
         }
         $errorMsg[] = $error_Msg;
         // 为会员添加积分
         if (isset($sdf_order['member_id']) && $sdf_order['member_id'] && $arrOrder['payed'] == $sdf_order['cur_amount']) {
             $arr_orders = $obj_orders->getList('*', array('order_id' => $rel_id));
             $arr_orders[0]['pay_status'] = '1';
             $is_change_point = true;
             // 扣除积分,使用积分
             $obj_reducte_point = kernel::service('b2c_member_point_reducte');
             $operator = $this->from == 'Back' ? $sdf['op_id'] : $sdf_order['member_id'];
             $policy_stage = $this->app->getConf("site.consume_point.stage");
             if ($arr_orders[0]['pay_status'] == '1' && $arr_orders[0]['ship_status'] == '1' && $policy_stage == '2') {
                 $stage = '1';
             } elseif ($arr_orders[0]['pay_status'] == '1' && $policy_stage == '1') {
                 $stage = '1';
             } else {
                 $stage = '0';
             }
             /** end **/
             if ($stage) {
                 $is_change_point = $obj_reducte_point->change_point($sdf_order['member_id'], 0 - intval($sdf_order['score_u']), $msg, 'order_pay_use', 1, $stage, $rel_id, $operator);
             }
             if (!$is_change_point) {
                 $status = 'failed';
                 return false;
             }
             $policy_stage = $this->app->getConf("site.get_policy.stage");
             if ($arr_orders[0]['pay_status'] == '1' && $arr_orders[0]['ship_status'] == '1' && $policy_stage == '2') {
                 $stage = '1';
             } elseif ($arr_orders[0]['pay_status'] == '1' && $policy_stage == '1') {
                 $stage = '1';
             } else {
                 $stage = '0';
             }
             // 获得积分
             $obj_add_point = kernel::service('b2c_member_point_add');
             if ($stage) {
                 $obj_add_point->change_point($sdf_order['member_id'], intval($sdf_order['score_g']), $msg, 'order_pay_get', 2, $stage, $rel_id, $operator);
             }
             // 增加经验值
             $obj_member = $this->app->model('members');
             $obj_member->change_exp($sdf_order['member_id'], floor($sdf_order['cur_amount']));
         }
         if ($pay_status == '1') {
             $sdf['pay_status'] = 'PAY_FINISH';
         } else {
             if ($pay_status == '2') {
                 $sdf['pay_status'] = 'PAY_TO_MEDIUM';
             } else {
                 if ($pay_status == '3') {
                     $sdf['pay_status'] = 'PAY_PART';
                 } else {
                     $sdf['pay_status'] = 'FAILED';
                 }
             }
         }
         $sdf['order_id'] = $rel_id;
         // 冻结库存
         if ($arrOrder['payed'] == $sdf_order['cur_amount']) {
             $this->app->setConf('system.goods.freez.time', '2');
             $store_mark = $this->app->getConf('system.goods.freez.time');
             // 所有的goods type 处理的服务的初始化.
             $arr_service_goods_type_obj = array();
             $arr_service_goods_type = kernel::servicelist('order_goodstype_operation');
             foreach ($arr_service_goods_type as $obj_service_goods_type) {
                 $goods_types = $obj_service_goods_type->get_goods_type();
                 $arr_service_goods_type_obj[$goods_types] = $obj_service_goods_type;
             }
             $arr_common_type = array('goods', 'gift');
             //门店自提 不检测库存,webpos不检测库存
             if ($store_mark == '2' && !in_array($sdf_order['shipping']['shipping_name'], NOFREEZ_SHIPPING_TYPE) && $sdf_order['branch_id'] == 0) {
                 $objGoods = $this->app->model('goods');
                 if ($sdf_order['order_objects']) {
                     foreach ($sdf_order['order_objects'] as $k => $v) {
                         if (in_array($v['obj_type'], $arr_common_type)) {
                             $order_items = array_merge($order_items, $v['order_items']);
                         } else {
                             // 扩展区块的商品预占库存处理
                             $str_service_goods_type_obj = $arr_service_goods_type_obj[$v['obj_type']];
                             $is_freeze = $str_service_goods_type_obj->freezeGoods($v);
                             if (!$is_freeze) {
                                 $status = 'failed';
                                 $msg = app::get('b2c')->_('商品库存不足!');
                                 return false;
                             }
                         }
                     }
                 }
                 // 判断是否已经发过货.
                 if ($sdf_order['ship_status'] == '1' || $sdf_order['ship_status'] == '2') {
                     foreach ($order_items as $key => $dinfo) {
                         if ($dinfo['products']['sendnum'] < $dinfo['products']['nums']) {
                             $semds = $objMath->number_plus(array($dinfo['nums'], $dinfo['sendnum']));
                             if ($semds > 0) {
                                 $arr_params = array('goods_id' => $dinfo['goods_id'], 'product_id' => $dinfo['products']['product_id'], 'quantity' => $semds);
                                 if ($dinfo['item_type'] == 'product') {
                                     $dinfo['item_type'] = 'goods';
                                 }
                                 $str_service_goods_type_obj = $arr_service_goods_type_obj[$dinfo['item_type']];
                                 $is_freeze = $str_service_goods_type_obj->freezeGoods($arr_params);
                                 if (!$is_freeze) {
                                     $status = 'failed';
                                     $msg = app::get('b2c')->_('商品库存不足!');
                                     return false;
                                 }
                             }
                         }
                     }
                 } else {
                     foreach ($order_items as $key => $dinfo) {
                         $arr_params = array('goods_id' => $dinfo['goods_id'], 'product_id' => $dinfo['products']['product_id'], 'quantity' => $dinfo['quantity']);
                         if ($dinfo['item_type'] == 'product') {
                             $dinfo['item_type'] = 'goods';
                         }
                         $str_service_goods_type_obj = $arr_service_goods_type_obj[$dinfo['item_type']];
                         $is_freeze = $str_service_goods_type_obj->freezeGoods($arr_params);
                         if (!$is_freeze) {
                             $status = 'failed';
                             $msg = app::get('b2c')->_('商品库存不足!');
                             return false;
                         }
                     }
                 }
             }
             //支付,处理其他app自身业务逻辑
             $arr_service_pay = kernel::servicelist("order_pay_operation");
             foreach ((array) $arr_service_pay as $obj_service_order_pay) {
                 if (method_exists($obj_service_order_pay, "check_order_info")) {
                     if (!$obj_service_order_pay->check_order_info($sdf_order, $message)) {
                         $status = 'failed';
                         $msg = $message;
                         return false;
                     }
                 }
             }
         }
         // 与中心交互
         $is_need_rpc = false;
         $obj_rpc_obj_rpc_request_service = kernel::servicelist('b2c.rpc_notify_request');
         foreach ($obj_rpc_obj_rpc_request_service as $obj) {
             if ($obj && method_exists($obj, 'rpc_judge_send')) {
                 if ($obj instanceof b2c_api_rpc_notify_interface) {
                     $is_need_rpc = $obj->rpc_judge_send($sdf_order);
                 }
             }
             if ($is_need_rpc) {
                 break;
             }
         }
         //if (app::get('b2c')->getConf('site.order.send_type') == 'false'&&$is_need_rpc){
         if ($is_need_rpc) {
             system_queue::instance()->publish('b2c_tasks_matrix_sendpayments', 'b2c_tasks_matrix_sendpayments', $sdf);
             //             	$obj_apiv = kernel::single('b2c_apiv_exchanges_request');
             //             	$obj_apiv->rpc_caller_request($sdf, 'orderpay');
         }
         $aUpdate['order_id'] = $rel_id;
         $aUpdate['paytime'] = date('Y-m-d', time());
         $aUpdate['money'] = $sdf['cur_money'];
         $aUpdate['email'] = !$sdf_order['member_id'] ? $sdf_order['consignee']['email'] : $arr_members['contact']['email'];
         $aUpdate['pay_status'] = $sdf['pay_status'];
         $aUpdate['is_frontend'] = $this->from == 'Back' ? false : true;
         $aUpdate['pay_account'] = $arr_members['pam_account']['login_name'];
         $obj_orders->fireEvent("payed", $aUpdate, $sdf_order['member_id']);
         if ($sdf['pay_app_id'] == 'deposit' && $is_save && $sdf['money'] != '0.00') {
             //计算精度
             bcscale(2);
             $member_id = $sdf_order['member_id'];
             // @author francis
             $member = kernel::database()->select("SELECT login_account FROM sdb_pam_members WHERE member_id={$member_id} AND login_type='mobile'");
             $deposit = app::get('b2c')->model('members')->getList('advance', array('member_id' => $member_id));
             if ($mobile = $member[0]['login_account']) {
                 $data = array('passport_id' => substr($member[0]['login_account'], -4), 'time' => date('Y年m月d日H时i分', time()), 'cost' => sprintf("%.2f", $sdf['money']), 'deposit' => sprintf("%.2f", $deposit[0]['advance']));
                 $sender = 'b2c_messenger_sms';
                 $tmpl = 'deposit-change';
                 $tmpl_name = 'messenger:b2c_messenger_sms/' . $tmpl;
                 $messengerModel = $this->app->model('member_messenger');
                 $messengerModel->addQueue($sender, $tmpl_name, (string) $mobile, $data, $tmpl, $sendType);
             }
             //发送微信消息推送 bySam 20150611
             $openid = kernel::database()->select("SELECT open_id from sdb_pam_bind_tag where member_id = {$member_id} ");
             if (isset($openid[0]['open_id'])) {
                 $openid = $openid[0]['open_id'];
                 $deposit = app::get('b2c')->model('members')->getList('advance', array('member_id' => $member_id));
                 $data = array('passport_id' => substr($openid, -4), 'time' => date('Y年m月d日H时i分', time()), 'cost' => sprintf("%.2f", $sdf['money']), 'deposit' => sprintf("%.2f", $deposit[0]['advance']));
                 $weixin_message = "尊敬的客户,您的品珍钱包(预存款) 于{$data['time']}发生支付交易,支出人民币{$data['cost']}元,当前账户余额{$data['deposit']}元。【品珍鲜活】";
                 $bind = app::get('weixin')->model('bind')->getRow('id', array('eid' => '247644', 'status' => 'active'));
                 $accesstoken = kernel::single('weixin_wechat')->get_basic_accesstoken($bind['id']);
                 $weixin_push_post_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$accesstoken}";
                 $weixin_push_post_data = array("touser" => $openid, "template_id" => "5C1fzNzlIqH4yjinmta-6S4nM19ujGN9EoWMPVh-lm4", "data" => array("first" => array("value" => $weixin_message, "color" => "#173177"), "tradeType" => array("value" => "预存款消费", "color" => "#173177"), "tradeDateTime" => array("value" => $data['time']), "curAmount" => array("value" => '¥' . $data['cost'] . '元')));
                 $weixin_push_post_data = json_encode($weixin_push_post_data);
                 $httpclient = kernel::single('base_httpclient');
                 $response = $httpclient->set_timeout(6)->post($weixin_push_post_url, $weixin_push_post_data);
             }
             // end
         }
     } else {
         $msg = app::get('b2c')->_('需要支付的订单号不存在!');
         $status = 'failed';
         return false;
     }
 }
Example #11
0
 /**
  * @description 删除评论与咨询后触发短信等事件
  * @access public
  * @param array $data
  * @return boolean
  */
 public function pre_recycle($data)
 {
     $ret = $this->app->getConf('messenger.actions.comments-delete');
     if (!$ret) {
         return true;
     }
     $action = explode(',', $ret);
     $emailTmpl = '';
     $msgboxTmpl = '';
     $smsTmpl = '';
     $systmpl = $this->app->model('member_systmpl');
     foreach ($data as $key => $value) {
         if (!$value['author_id']) {
             continue;
         }
         $member = kernel::single('b2c_user_object')->get_pam_data('*', $value['author_id']);
         //发邮件
         if (in_array('b2c_messenger_email', $action) && $member['email']) {
             if (!$emailTmpl) {
                 $emailTmpl = $systmpl->fetch('messenger:b2c_messenger_email/comments-delete', array());
             }
             $worker = 'b2c_tasks_sendemail';
             $params['acceptor'] = $member['email'];
             $params['body'] = $emailTmpl;
             $params['title'] = $this->app->_('删除评论与咨询');
         }
         //发站内信
         if (in_array('b2c_messenger_msgbox', $action)) {
             if (!$msgboxTmpl) {
                 $msgboxTmpl = $systmpl->fetch('messenger:b2c_messenger_msgbox/comments-delete', array());
             }
             $worker = 'b2c_tasks_sendmsg';
             $params['member_id'] = $value['author_id'];
             $params['data']['content'] = $msgboxTmpl;
             $params['data']['title'] = $this->app->_('删除评论与咨询');
             $params['name'] = $value['author'];
         }
         //发短信
         if (in_array('b2c_messenger_sms', $action) && $member['mobile']) {
             if (!$smsTmpl) {
                 $smsTmpl = $systmpl->fetch('messenger:b2c_messenger_sms/comments-delete', array());
             }
             $worker = 'b2c_tasks_sendsms';
             $params['mobile_number'] = $member['mobile'];
             $params['data']['title'] = $this->app->_('删除评论与咨询');
             $params['data']['content'] = $smsTmpl;
         }
         if ($worker) {
             system_queue::instance()->publish($worker, $worker, $params);
         }
     }
     return true;
 }
Example #12
0
 public function setUp()
 {
     ob_implicit_flush(1);
     $this->obj_queue = system_queue::instance();
 }
Example #13
0
 /**
  * 当task进程通过finishi() 或者 return string 将任务处理的结果发送给worker进程时,回调此方法
  */
 public function onFinish($server, $taskId, $data)
 {
     echo 4;
     $result = unserialize($data);
     return system_queue::instance()->ack($result['id']);
 }
Example #14
0
 function send()
 {
     $this->begin('index.php?app=b2c&ctl=admin_goods_sto&act=index');
     /** 判断是否能够发送 **/
     $conf_goods_notify = $this->app->getConf('messenger.actions.goods-notify');
     if (!$conf_goods_notify) {
         $this->end(false, app::get('b2c')->_('必须在邮件短信管理里面勾选-手机短信,站内消息或者电子邮件其中一项才可以!'));
     }
     $arr_conf_goods_notify = explode(',', $conf_goods_notify);
     $systmpl = $this->app->model('member_systmpl');
     $obj_product = app::get('b2c')->model('products');
     $member_goods = app::get('b2c')->model('member_goods');
     if ($_POST['isSelectedAll'] == '_ALL_') {
         $aGnotify = array();
         $aData = $member_goods->getList('gnotify_id');
         foreach ((array) $aData as $key => $val) {
             $aGnotify[] = $val['gnotify_id'];
         }
     } else {
         $aGnotify = $_POST['gnotify_id'];
     }
     foreach ($aGnotify as $gnid) {
         $data = $member_goods->dump($gnid);
         if ($data['member_id']) {
             $member_obj = $this->app->model('members');
             $login_name = kernel::single('b2c_user_object')->get_member_name(null, $data['member_id']);
         } else {
             $login_name = app::get('b2c')->_("顾客");
         }
         $goods = $obj_product->dump($data['product_id']);
         $obj['goods_name'] = $goods['name'];
         $obj['goods_id'] = $goods['goods_id'];
         $obj['username'] = $login_name;
         $obj['url'] = app::get('site')->router()->gen_url(array('app' => 'b2c', 'ctl' => 'site_product', 'full' => 1, 'act' => 'index', 'arg' => $data['product_id']));
         if (in_array('b2c_messenger_email', $arr_conf_goods_notify)) {
             $content = $systmpl->fetch('messenger:b2c_messenger_email/goods-notify', $obj);
             $params = array('acceptor' => $data['email'], 'body' => $content, 'title' => app::get('b2c')->_('到货通知'), 'product_id' => $data['product_id'], 'gnotify_id' => $gnid);
             if (!system_queue::instance()->publish('b2c_tasks_sendemail', 'b2c_tasks_sendemail', $params)) {
                 $this->end(false, app::get('b2c')->_('操作失败!'));
             }
         }
         if ($data['member_id']) {
             if (in_array('b2c_messenger_msgbox', $arr_conf_goods_notify)) {
                 $aTmp['content'] = $systmpl->fetch('messenger:b2c_messenger_msgbox/goods-notify', $obj);
                 $aTmp['title'] = app::get('b2c')->_("商品到货通知");
                 $params = array('member_id' => $data['member_id'], 'data' => $aTmp, 'name' => $login_name, 'gnotify_id' => $gnid);
                 if (!system_queue::instance()->publish('b2c_tasks_sendmsg', 'b2c_tasks_sendmsg', $params)) {
                     $this->end(false, app::get('b2c')->_('操作失败!'));
                 }
             }
         }
         //发到货通知到手机
         if (in_array('b2c_messenger_sms', $arr_conf_goods_notify) && $data['cellphone']) {
             $aSms['content'] = $systmpl->fetch('messenger:b2c_messenger_sms/goods-notify', $obj);
             $aSms['title'] = app::get('b2c')->_("商品到货通知");
             $aSms['sendType'] = 'fan-out';
             $params = array('mobile_number' => $data['cellphone'], 'data' => $aSms);
             if (!system_queue::instance()->publish('b2c_tasks_sendsms', 'b2c_tasks_sendsms', $params)) {
                 $this->end(false, app::get('b2c')->_('操作失败!'));
             }
         }
     }
     $this->end(ture, app::get('b2c')->_('操作成功!'));
 }
Example #15
0
    /**
     * 重新生成图片入口
     * @param nulll
     * @return string html js刷新finder
     */
    function rebuild()
    {
        $ui = new base_component_ui($this);
        if ($_POST['size']) {
            parse_str($_POST['filter'], $filter);
            $params = array('filter' => $filter, 'watermark' => $_POST['watermark'], 'size' => $_POST['size'], 'queue_time' => time());
            system_queue::instance()->publish('image_tasks_imagerebuild', 'image_tasks_imagerebuild', $params);
            header('Content-Type:text/jcmd; charset=utf-8');
            echo '{success:"' . app::get('image')->_('执行成功') . '"}';
        } else {
            $html .= $ui->form_start(array('id' => 'rebuild_form', 'method' => 'post'));
            $size = array('L' => app::get('image')->_('大图'), 'M' => app::get('image')->_('中图'), 'S' => app::get('image')->_('小图'));
            foreach ($size as $k => $v) {
                $html .= $ui->form_input(array('title' => app::get('image')->_('生成') . $v, 'type' => 'checkbox', 'name' => 'size[]', 'value' => $k, 'checked' => 'checked'));
            }
            $html .= '<tr><td colspan="2" style="height:1px;background:#ccc;overflow:hidden;padding:0"></td><tr>';
            $filter = $_POST;
            unset($filter['_finder']);
            $filter = htmlspecialchars(utils::http_build_query($filter));
            $html .= $ui->form_input(array('title' => app::get('image')->_('使用水印'), 'type' => 'bool', 'name' => 'watermark', 'value' => 1));
            $html .= '<tr><td><input type="hidden" name="filter" value="' . $filter . '" /></td></tr>';
            $html .= $ui->form_end();
            echo $html;
            echo <<<EOF
<script>
   \$('rebuild_form').store('target',{

\t\tonComplete:function(){
\t\t\t\t \$('rebuild_form').getParent('.dialog').retrieve('instance').close();

\t\t}

   });

</script>
EOF;
        }
    }
Example #16
0
 /**
  * @description 订阅邮件发送函数
  * @access public
  * @param void
  * @return void
  */
 public function toSend()
 {
     $this->begin();
     $params = $this->_request->get_post();
     if (empty($params['selTmpl'])) {
         $this->end(false, $this->app->_('请选择邮件模板'));
     }
     if (empty($params['emailtype'])) {
         $this->end(false, $this->app->_('请发送邮件地址方式'));
     }
     if ($params['emailtype'] == 2 && empty($params['emailsel'])) {
         $this->end(false, $this->app->_('请选择自定义邮件地址'));
     }
     $emailcontModel = $this->app->model('emailcont');
     switch ($params['emailtype']) {
         case 1:
             //选取所有订阅邮箱地址
             $params = array('selTmpl' => $params['selTmpl']);
             //选择的模板
             // 'worker'=>'emailsubs_queue.send_mail',
             //插入列表状态
             if (!system_queue::instance()->publish('emailbus_tasks_sendemail', 'emailbus_tasks_sendemail', $params)) {
                 $this->end(false, $this->app->_('操作失败!'));
             }
             //更新邮件状态
             $emailcontModel->update(array('ec_ifsend' => '1', 'ec_sendtime' => time()), array('ec_id' => $params['selTmpl']));
             $this->end(true, $this->app->_('操作成功!'));
             break;
         case 2:
             //自定义选取订阅邮箱地址
             //邮件内容
             $emailcont = $emailcontModel->dump($params['selTmpl']);
             //邮件模板
             $emailtmplModel = $this->app->model('emailtmpl');
             //会员模板
             $tmpl_member = $emailtmplModel->getEmailTmpl('mem');
             //非会员模板
             $tmpl_unmember = $emailtmplModel->getEmailTmpl('unmem');
             $emailaddrModel = $this->app->model('emailaddr');
             $emailaddrList = $emailaddrModel->getList('ea_id,ea_email,uname', array('ea_id' => $params['emailsel']));
             foreach ($emailaddrList as $key => $value) {
                 if ($value['uname']) {
                     $body = $emailtmplModel->dealwithTmpl($emailcont['ec_content'], $tmpl_member, $value['ea_email'], $value['uname']);
                 } else {
                     $body = $emailtmplModel->dealwithTmpl($emailcont['ec_content'], $tmpl_unmember, $value['ea_email']);
                 }
                 $params = array('acceptor' => $value['ea_email'], 'body' => $body, 'title' => $emailcont['ec_title']);
                 if (!system_queue::instance()->publish('b2c_tasks_sendemail', 'b2c_tasks_sendemail', $params)) {
                     $this->end(false, $this->app->_('操作失败!'));
                 }
             }
             $emailcontModel->update(array('ec_ifsend' => '1', 'ec_sendtime' => time()), array('ec_id' => $params['selTmpl']));
             $this->end(true, $this->app->_('操作成功!'));
             break;
         default:
             $this->end(false, $this->app->_('操作失败!'));
             break;
     }
 }
Example #17
0
 function turn_to_sdf(&$cursor_id, $params)
 {
     base_kvstore::instance($params['app'] . '_' . $params['mdl'])->fetch($params['file_name'], $contents);
     base_kvstore::instance($params['app'] . '_' . $params['mdl'])->fetch($params['file_name'] . '_sdf', $sdfContents);
     base_kvstore::instance($params['app'] . '_' . $params['mdl'])->fetch($params['file_name'] . '_error', $errorContents);
     //   base_kvstore::instance($params['app'].'_'.$params['mdl'])->fetch($params['file_name'].'_msg',$msgContents);
     $contents = unserialize($contents);
     $sdfContents = unserialize($sdfContents);
     $errorContents = unserialize($errorContents);
     // $msgContents = unserialize( $msgContents );
     reset($contents);
     if (empty($contents[0][0])) {
         $msg = array('error' => app::get('desktop')->_('瀵煎叆鍟嗗搧涓虹┖'));
         $msgList['error'][] = $msg['error'];
         return $msgList;
     }
     $msgList = array();
     $o = app::get($params['app'])->model($params['mdl']);
     $oIo = kernel::servicelist('desktop_io');
     foreach ($oIo as $aIo) {
         if ($aIo->io_type_name == $params['file_type']) {
             $importType = $aIo;
             break;
         }
     }
     unset($oIo);
     $objFunc = 'prepared_import_' . $importType->io_type_name . '_obj';
     $rowFunc = 'prepared_import_' . $importType->io_type_name . '_row';
     $i = 0;
     $tmpl = array();
     $tTmpl = array();
     $gTitle = array();
     $data = array();
     $tObjContent = array();
     $errorObj = false;
     $importType->prepared_import($params['app'], $params['mdl']);
     while (true) {
         $curContent = array_shift($contents);
         $newObjFlag = false;
         $msg = '';
         $rowData = $o->{$rowFunc}($curContent, $data['title'], $tmpl, $mark, $newObjFlag, $msg);
         if ($msg['error']) {
             $msgList['error'][] = $msg['error'];
         }
         if ($msg['warning']) {
             foreach ($msg['warning'] as $mk => $mv) {
                 $msgList['warning'][] = $mv;
             }
         }
         if ($newObjFlag) {
             if ($errorObj) {
                 $errorList[] = $tObjContent;
                 $errorObj = false;
             }
             $tObjContent = array();
             if ($mark != 'title') {
                 $msg = '';
                 $saveData = $o->{$objFunc}($data, $mark, $tmpl, $msg);
                 if ($msg['error']) {
                     $msgList['error'][] = $msg['error'];
                 }
                 if ($msg['warning']) {
                     foreach ($msg['warning'] as $mk => $mv) {
                         $msgList['warning'][] = $mv;
                     }
                 }
                 if ($saveData === false) {
                     return $msgList;
                     $errorContents[] = $gTitle;
                     foreach ($tObjContent as $ck => $cv) {
                         $errorContents[] = $cv;
                     }
                 }
                 if ($saveData) {
                     $sdfContents[] = $saveData;
                 }
                 if ($mark) {
                     eval('$data["' . implode('"]["', explode('/', $mark)) . '"] = array();');
                 }
             } else {
                 $tTmpl = $rowData;
                 $gTitle = $curContent;
             }
             /*
                             if( ++$i == 100 ){
                $rs = 1;
                break;
                             }
             */
             $tObjContent[] = $curContent;
             if ($rowData === false) {
                 return $msgList;
                 $errorObj = true;
             }
         }
         if ($mark) {
             if ($mark == 'title') {
                 eval('$data["' . implode('"]["', explode('/', $mark)) . '"] = $rowData;');
             } else {
                 eval('$data["' . implode('"]["', explode('/', $mark)) . '"][] = $rowData;');
             }
         }
         if (!current($contents) && current($data['contents'])) {
             $saveData = $o->{$objFunc}($data, $mark, $tmpl, $msg);
             if ($msg['error']) {
                 $msgList['error'][] = $msg['error'];
             }
             if ($msg['warning']) {
                 foreach ($msg['warning'] as $mk => $mv) {
                     $msgList['warning'][] = $mv;
                 }
             }
             if ($saveData === false) {
                 return $msgList;
                 $errorContents[] = $gTitle;
                 foreach ($tObjContent as $ck => $cv) {
                     $errorContents[] = $cv;
                 }
             }
             if ($saveData) {
                 $sdfContents[] = $saveData;
             }
             if ($mark) {
                 eval('$data["' . implode('"]["', explode('/', $mark)) . '"] = array();');
             }
             //   break;
         }
         if (!$curContent) {
             break;
         }
     }
     if (!$contents) {
         $rs = 0;
     } else {
         $contents = array_unshift($contents, $gTitle);
     }
     base_kvstore::instance($params['app'] . '_' . $params['mdl'])->store($params['file_name'], serialize($contents));
     base_kvstore::instance($params['app'] . '_' . $params['mdl'])->store($params['file_name'] . '_sdf', serialize($sdfContents));
     base_kvstore::instance($params['app'] . '_' . $params['mdl'])->store($params['file_name'] . '_error', serialize($errorContents));
     if (!$rs) {
         $params = array('app' => $params['app'], 'mdl' => $params['mdl'], 'file_name' => $params['file_name']);
         system_queue::instance()->publish('desktop_tasks_runimport', 'desktop_tasks_runimport', $params);
     }
     if ($msgList['error'] || $msgList['warning']) {
         return $msgList;
     }
     return 0;
 }
Example #18
0
set_time_limit(0);
$root_dir = realpath(dirname(__FILE__) . '/../../');
$script_dir = $root_dir . '/script';
// 修改默认的config配置
define('LOG_LEVEL', LOG_INFO);
define('LOG_TYPE', 3);
define('LOG_FILE', $root_dir . '/data/logs/queue/{date}.php');
//-------------------------------------------------------------------------------------
require_once $script_dir . "/lib/runtime.php";
set_error_handler('error_handler');
//-------------------------------------------------------------------------------------
if (!isset($argv[1])) {
    echo "Hey boy or girl, Please give me the queue name!\n";
    exit;
}
$queue_name = $argv[1];
$queues = system_queue::instance()->get_config('queues');
if ($num = (int) $queues[$queue_name]['thread']) {
    system_queue_consumer::instance('proc')->exec($queue_name, $num);
}
//-------------------------------------------------------------------------------------
function error_handler($code, $msg, $file, $line)
{
    if ($code == ($code & (E_ERROR ^ E_USER_ERROR ^ E_USER_WARNING))) {
        logger::error(sprintf('ERROR:%d @ %s @ file:%s @ line:%d', $code, $msg, $file, $line));
        if ($code == ($code & (E_ERROR ^ E_USER_ERROR))) {
            exit;
        }
    }
    return true;
}
Example #19
0
 public function send_payments()
 {
     if (!$_POST['payment_id']) {
         echo '{failed:"' . app::get('b2c')->_('发送支付号不存在!') . '",msg:"' . app::get('b2c')->_('发送支付号不存在!') . '"}';
         exit;
     }
     $app_ectools = app::get('ectools');
     $oPayment = $app_ectools->model('payments');
     $subsdf = array('orders' => array('*'));
     $sdf_payment = $oPayment->dump($_POST['payment_id'], '*', $subsdf);
     /** 开始发送 **/
     if (!$sdf_payment) {
         echo '{failed:"' . app::get('b2c')->_('发送支付单不存在!') . '",msg:"' . app::get('b2c')->_('发送支付单不存在!') . '"}';
         exit;
     }
     system_queue::instance()->publish('b2c_tasks_matrix_sendpayments', 'b2c_tasks_matrix_sendpayments', $sdf_payment);
     echo '{success:"' . app::get('b2c')->_('成功!') . '",msg:"' . app::get('b2c')->_('成功!') . '"}';
     exit;
 }
Example #20
0
// | Licensed ( http://www.vmcshop.com/licensed)
// +----------------------------------------------------------------------
// | Author: Shanghai ChenShang Software Technology Co., Ltd.
// +----------------------------------------------------------------------
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit(0);
//-------------------------------------------------------------------------------------
require_once realpath(dirname(dirname(dirname(__FILE__)))) . '/process/lib/runtime.php';
set_error_handler('error_handler');
//-------------------------------------------------------------------------------------
if (!isset($argv[1])) {
    echo "Hey boy or girl, Please give me the queue name!\n";
    exit;
}
$queue_name = $argv[1];
if ($queue_message = system_queue::instance()->get($queue_name)) {
    system_queue::instance()->run_task($queue_message);
    //echo $queue_message->get_id();
    system_queue::instance()->ack($queue_message);
}
//-------------------------------------------------------------------------------------
function error_handler($code, $msg, $file, $line)
{
    if ($code == ($code & (E_ERROR ^ E_USER_ERROR ^ E_USER_WARNING))) {
        logger::error(sprintf('ERROR:%d @ %s @ file:%s @ line:%d', $code, $msg, $file, $line));
        if ($code == ($code & (E_ERROR ^ E_USER_ERROR))) {
            exit;
        }
    }
    return true;
}
Example #21
0
 public function setItemStatus()
 {
     $postData = input::get();
     try {
         if (!($itemId = $postData['item_id'])) {
             $msg = app::get('topshop')->_('商品id不能为空');
             return $this->splash('error', null, $msg, true);
         }
         if ($postData['type'] == 'tosale') {
             $shopdata = app::get('topshop')->rpcCall('shop.get', array('shop_id' => $this->shopId), 'seller');
             if (empty($shopdata) || $shopdata['status'] == "dead") {
                 $msg = app::get('topshop')->_('抱歉,您的企业处于关闭状态,不能发布(上架)商品');
                 return $this->splash('error', null, $msg, true);
             }
             $status = 'onsale';
             $msg = app::get('topshop')->_('上架成功');
         } elseif ($postData['type'] == 'tostock') {
             $status = 'instock';
             $msg = app::get('topshop')->_('下架成功');
         } else {
             return $this->splash('error', null, '非法操作!', true);
         }
         $params['item_id'] = intval($itemId);
         $params['shop_id'] = intval($this->shopId);
         $params['approve_status'] = $status;
         app::get('topshop')->rpcCall('item.sale.status', $params);
         $queue_params['item_id'] = intval($itemId);
         $queue_params['shop_id'] = intval($this->shopId);
         //发送到货通知的邮件
         if ($status == "onsale") {
             system_queue::instance()->publish('sysitem_tasks_userItemNotify', 'sysitem_tasks_userItemNotify', $queue_params);
         }
         $url = url::action('topshop_ctl_item@itemList');
         return $this->splash('success', $url, $msg, true);
     } catch (Exception $e) {
         return $this->splash('error', null, $e->getMessage(), true);
     }
 }
Example #22
0
 /**
  * 消息入口.
  *
  * @param mixed $action_name 消息action_name
  * @param mixed $tmpl_data   用于组织消息内容的数据
  * @param mixed array $target = array('member_id'=>'','mobile'=>'','email'=>'')
  */
 public function trigger($action_name, $tmpl_data, $target = array())
 {
     $actions = $this->get_actions();
     $action = $actions[$action_name];
     if (!$action) {
         return;
     }
     $level = $action['level'];
     $label = $action['label'];
     $sender_list = $this->get_sender_list();
     foreach ($sender_list as $sender_class => $sender) {
         $tmpl_name = 'messenger:' . $sender_class . '/' . $action_name;
         //发送过滤
         if (isset($action[$sender_class]['exclude']) && in_array($sender_class, $action[$sender_class]['exclude'])) {
             continue;
         }
         if ($this->app->getConf('messenger_disabled_' . $sender_class . '_' . $action_name) !== true || $action['lock']) {
             if ($sender && !empty($target)) {
                 //开始执行
                 if ($level > 10) {
                     $this->action($tmpl_name, $tmpl_data, $target);
                 } else {
                     //进入队列执行
                     $queue_params = array('tmpl_name' => $tmpl_name, 'tmpl_data' => $tmpl_data, 'target' => $target);
                     system_queue::instance()->publish('b2c_tasks_messenger', 'b2c_tasks_messenger', $queue_params);
                 }
             }
         }
     }
 }
Example #23
0
 function insert_queue()
 {
     #$this->begin('index.php?app=b2c&ctl=admin_member&act=index');
     $this->begin();
     $aEmail = json_decode($_POST['aEmail']);
     $service = kernel::service("b2c.messenger.email_content");
     if (is_object($service)) {
         if (method_exists($service, 'get_content')) {
             $_POST['content'] = $service->get_content($_POST['content']);
         }
     }
     $content = trim($_POST['content'], '&nbsp;');
     if (empty($content)) {
         $this->end(false, app::get('b2c')->_('邮件内容不能为空!'));
     }
     foreach ($aEmail as $key => $val) {
         $params = array('acceptor' => $val, 'body' => $_POST['content'], 'title' => $_POST['title']);
         if (!system_queue::instance()->publish('b2c_tasks_sendemail', 'b2c_tasks_sendemail', $params)) {
             $this->end(false, app::get('b2c')->_('操作失败!'));
         }
     }
     $this->end(true, app::get('b2c')->_('操作成功!'));
 }
Example #24
0
 private function __order_payment($rel_id, &$sdf, &$status = 'succ', &$msg = '')
 {
     $objMath = kernel::single('ectools_math');
     $obj_orders = $this->app->model('orders');
     $subsdf = array('order_objects' => array('*', array('order_items' => array('*', array(':products' => '*')))));
     $sdf_order = $obj_orders->dump($rel_id, '*', $subsdf);
     $order_items = array();
     if ($sdf_order) {
         if ($sdf_order['member_id']) {
             $arr_members = kernel::single('b2c_user_object')->get_pam_data('*', $sdf_order['member_id']);
             if (isset($arr_members['local'])) {
                 $login_name = $arr_members['local'];
             } elseif (isset($arr_members['email'])) {
                 $login_name = $arr_members['email'];
             } else {
                 $login_name = $arr_members['mobile'];
             }
             $this->str_op_id = $sdf_order['member_id'];
             $this->str_op_name = $login_name;
         } else {
             $this->str_op_id = '0';
             $this->str_op_name = '';
         }
         if ($sdf_order['pay_status'] == '1') {
             $msg = app::get('b2c')->_('该订单已经支付,无需重新支付!');
             $status = 'succ';
             return true;
         } else {
             if ($sdf_order['pay_status'] == '2' && $status == "progress") {
                 $msg = app::get('b2c')->_('该订单已经支付担保方!');
                 $status = 'failed';
                 return false;
             }
         }
         // Order information update.
         if ($objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])) < $sdf_order['cur_amount'] && $status != 'failed') {
             $pay_status = '3';
         } else {
             if ($status == 'succ' || $status == 'progress') {
                 if ($status == 'succ') {
                     $pay_status = '1';
                 } else {
                     $pay_status = '2';
                 }
             } else {
                 if ($objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])) > $sdf_order['cur_amount']) {
                     $msg = app::get('b2c')->_('支付金额超过需要支付的总金额!');
                     $status = 'failed';
                     return false;
                 }
                 $pay_status = '0';
             }
         }
         if ($sdf['status'] != 'progress' && $objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])) > $sdf_order['cur_amount']) {
             $msg = app::get('b2c')->_('支付金额超过需要支付的总金额,不能支付!');
             $status = 'failed';
             return false;
         }
         $arrOrder = array('order_id' => $rel_id, 'payment' => $sdf['pay_app_id'], 'payed' => $objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])) > $sdf_order['cur_amount'] ? $sdf_order['cur_amount'] : $objMath->number_plus(array($sdf_order['payed'], $sdf['cur_money'])), 'pay_status' => $pay_status);
         // 支付完了,预存款
         if ($sdf['pay_app_id'] == 'deposit') {
             $objAdvance = $this->app->model("member_advance");
             $is_frontend = $this->from == 'Back' ? false : true;
             $status = $objAdvance->deduct($sdf_order['member_id'], $sdf['money'], app::get('b2c')->_('预存款支付订单'), $msg, $sdf['payment_id'], $rel_id, 'deposit', $sdf_order['memo'], $is_frontend);
             $error_Msg = $msg;
             if (!$status) {
                 return false;
             }
         } else {
             $error_Msg = $status == 'succ' || $status === true ? app::get('b2c')->_("订单号:") . $rel_id . ' ' . $arrPayments['app_name'] . app::get('b2c')->_("支付交易号: ") . $sdf['trade_no'] . app::get('b2c')->_(",交易成功!") : app::get('b2c')->_("订单号:") . $rel_id . ' ' . $arrPayments['app_name'] . app::get('b2c')->_("支付交易失败!");
         }
         $is_save = $obj_orders->update($arrOrder, array('order_id' => $rel_id));
         if (!$is_save) {
             $msg = app::get('b2c')->_('订单支付状态保存失败!');
             return false;
         }
         if (!$obj_orders->db->affect_row()) {
             $msg = app::get('b2c')->_('订单重复支付!');
             return false;
         }
         $errorMsg[] = $error_Msg;
         // 为会员添加积分
         if (isset($sdf_order['member_id']) && $sdf_order['member_id'] && $arrOrder['payed'] == $sdf_order['cur_amount'] && $pay_status == 1) {
             $arr_orders = $obj_orders->getList('*', array('order_id' => $rel_id));
             $arr_orders[0]['pay_status'] = '1';
             $is_change_point = true;
             // 扣除积分,使用积分
             $obj_reducte_point = kernel::service('b2c_member_point_reducte');
             $operator = $this->from == 'Back' ? $sdf['op_id'] : $sdf_order['member_id'];
             $policy_stage = $this->app->getConf("site.consume_point.stage");
             if ($arr_orders[0]['pay_status'] == '1' && $arr_orders[0]['ship_status'] == '1' && $policy_stage == '2') {
                 $stage = '1';
             } elseif ($arr_orders[0]['pay_status'] == '1' && $policy_stage == '1') {
                 $stage = '1';
             } else {
                 $stage = '0';
             }
             /** end **/
             if ($stage) {
                 $is_change_point = $obj_reducte_point->change_point($sdf_order['member_id'], 0 - intval($sdf_order['score_u']), $msg, 'order_pay_use', 1, $stage, $rel_id, $operator);
             }
             if (!$is_change_point) {
                 $status = 'failed';
                 return false;
             }
             $policy_stage = $this->app->getConf("site.get_policy.stage");
             if ($arr_orders[0]['pay_status'] == '1' && $arr_orders[0]['ship_status'] == '1' && $policy_stage == '2') {
                 $stage = '1';
             } elseif ($arr_orders[0]['pay_status'] == '1' && $policy_stage == '1') {
                 $stage = '1';
             } else {
                 $stage = '0';
             }
             // 获得积分
             $obj_add_point = kernel::service('b2c_member_point_add');
             if ($stage) {
                 $obj_add_point->change_point($sdf_order['member_id'], intval($sdf_order['score_g']), $msg, 'order_pay_get', 2, $stage, $rel_id, $operator);
             }
             // 增加经验值
             $obj_member = $this->app->model('members');
             if ($status == "succ") {
                 $obj_member->change_exp($sdf_order['member_id'], floor($sdf_order['cur_amount']));
             }
         }
         if ($pay_status == '1') {
             $sdf['pay_status'] = 'PAY_FINISH';
         } else {
             if ($pay_status == '2') {
                 $sdf['pay_status'] = 'PAY_TO_MEDIUM';
             } else {
                 if ($pay_status == '3') {
                     $sdf['pay_status'] = 'PAY_PART';
                 } else {
                     $sdf['pay_status'] = 'FAILED';
                 }
             }
         }
         $sdf['order_id'] = $rel_id;
         // 冻结库存
         if ($arrOrder['payed'] == $sdf_order['cur_amount']) {
             $store_mark = $this->app->getConf('system.goods.freez.time');
             // 所有的goods type 处理的服务的初始化.
             $arr_service_goods_type_obj = array();
             $arr_service_goods_type = kernel::servicelist('order_goodstype_operation');
             foreach ($arr_service_goods_type as $obj_service_goods_type) {
                 $goods_types = $obj_service_goods_type->get_goods_type();
                 $arr_service_goods_type_obj[$goods_types] = $obj_service_goods_type;
             }
             $arr_common_type = array('goods', 'gift');
             if ($store_mark == '2') {
                 $objGoods = $this->app->model('goods');
                 if ($sdf_order['order_objects']) {
                     foreach ($sdf_order['order_objects'] as $k => $v) {
                         if (in_array($v['obj_type'], $arr_common_type)) {
                             $order_items = array_merge($order_items, $v['order_items']);
                         } else {
                             // 扩展区块的商品预占库存处理
                             $str_service_goods_type_obj = $arr_service_goods_type_obj[$v['obj_type']];
                             $is_freeze = $str_service_goods_type_obj->freezeGoods($v);
                             if (!$is_freeze) {
                                 $status = 'failed';
                                 $msg = app::get('b2c')->_('商品库存不足!');
                                 return false;
                             }
                         }
                     }
                 }
                 // 判断是否已经发过货.
                 if ($sdf_order['ship_status'] == '1' || $sdf_order['ship_status'] == '2') {
                     foreach ($order_items as $key => $dinfo) {
                         if ($dinfo['products']['sendnum'] < $dinfo['products']['nums']) {
                             $semds = $objMath->number_plus(array($dinfo['nums'], $dinfo['sendnum']));
                             if ($semds > 0) {
                                 $arr_params = array('goods_id' => $dinfo['goods_id'], 'product_id' => $dinfo['products']['product_id'], 'quantity' => $semds);
                                 if ($dinfo['item_type'] == 'product') {
                                     $dinfo['item_type'] = 'goods';
                                 }
                                 $str_service_goods_type_obj = $arr_service_goods_type_obj[$dinfo['item_type']];
                                 $is_freeze = $str_service_goods_type_obj->freezeGoods($arr_params);
                                 if (!$is_freeze) {
                                     $status = 'failed';
                                     $msg = app::get('b2c')->_('商品库存不足!');
                                     return false;
                                 }
                             }
                         }
                     }
                 } else {
                     foreach ($order_items as $key => $dinfo) {
                         $arr_params = array('goods_id' => $dinfo['goods_id'], 'product_id' => $dinfo['products']['product_id'], 'quantity' => $dinfo['quantity']);
                         if ($dinfo['item_type'] == 'product') {
                             $dinfo['item_type'] = 'goods';
                         }
                         $str_service_goods_type_obj = $arr_service_goods_type_obj[$dinfo['item_type']];
                         $is_freeze = $str_service_goods_type_obj->freezeGoods($arr_params);
                         if (!$is_freeze) {
                             $status = 'failed';
                             $msg = app::get('b2c')->_('商品库存不足!');
                             return false;
                         }
                     }
                 }
             }
             //支付,处理其他app自身业务逻辑
             $arr_service_pay = kernel::servicelist("order_pay_operation");
             foreach ((array) $arr_service_pay as $obj_service_order_pay) {
                 if (method_exists($obj_service_order_pay, "check_order_info")) {
                     if (!$obj_service_order_pay->check_order_info($sdf_order, $message)) {
                         $status = 'failed';
                         $msg = $message;
                         return false;
                     }
                 }
             }
         }
         // 与中心交互
         $is_need_rpc = false;
         $obj_rpc_obj_rpc_request_service = kernel::servicelist('b2c.rpc_notify_request');
         foreach ($obj_rpc_obj_rpc_request_service as $obj) {
             if ($obj && method_exists($obj, 'rpc_judge_send')) {
                 if ($obj instanceof b2c_api_rpc_notify_interface) {
                     $is_need_rpc = $obj->rpc_judge_send($sdf_order);
                 }
             }
             if ($is_need_rpc) {
                 break;
             }
         }
         //if (app::get('b2c')->getConf('site.order.send_type') == 'false'&&$is_need_rpc){
         if ($is_need_rpc) {
             system_queue::instance()->publish('b2c_tasks_matrix_sendpayments', 'b2c_tasks_matrix_sendpayments', $sdf);
         }
         $aUpdate['order_id'] = $rel_id;
         $aUpdate['paytime'] = date('Y-m-d', time());
         $aUpdate['money'] = $sdf['cur_money'];
         $aUpdate['email'] = !$sdf_order['member_id'] ? $sdf_order['consignee']['email'] : $arr_members['email'];
         $aUpdate['pay_status'] = $sdf['pay_status'];
         $aUpdate['is_frontend'] = $this->from == 'Back' ? false : true;
         $aUpdate['pay_account'] = $login_name;
         $obj_orders->fireEvent("payed", $aUpdate, $sdf_order['member_id']);
     } else {
         $msg = app::get('b2c')->_('需要支付的订单号不存在!');
         $status = 'failed';
         return false;
     }
 }
Example #25
0
 /**
  * 记录平台操作日志
  *
  * @param $lang 日志语言包
  * @param $status 成功失败状态
  * @param $admin_name
  * @param $admin_id
  */
 protected final function adminlog($memo = '', $status = 1)
 {
     // 开启了才记录操作日志
     if (ADMIN_OPERATOR_LOG !== true) {
         return;
     }
     $queue_params = array('admin_userid' => $this->user->get_id(), 'admin_username' => $this->user->get_login_name(), 'created_time' => time(), 'memo' => $memo, 'status' => $status ? 1 : 0, 'router' => request::fullurl(), 'ip' => request::getClientIp());
     return system_queue::instance()->publish('system_tasks_adminlog', 'system_tasks_adminlog', $queue_params);
 }
Example #26
0
 /**
  * 订单保存.
  *
  * @param array order_sdf
  * @param string message
  *
  * @return bool
  */
 public function save(&$sdf, &$msg = '')
 {
     $mdl_order = $this->app->model('orders');
     //must Insert
     $result = $mdl_order->save($sdf, null, true);
     if (!$result) {
         $msg = '订单未能保存成功';
         return false;
     } else {
         //订单创建时同步扩展服务
         foreach (vmc::servicelist('b2c.order.create.finish') as $service) {
             if (!$service->exec($sdf, $msg)) {
                 //记录日志,不中断
                 logger::error($sdf['order_id'] . '创建出错!' . $msg);
             }
         }
         //订单相关业务异步处理队列
         system_queue::instance()->publish('b2c_tasks_order_related', 'b2c_tasks_order_aftercreate', $sdf);
         return true;
     }
 }