function post_updated_do_action($post_id)
{
    //Get the value of the 'product_id' field
    //get_post_meta ( int $post_id, string $key = '', bool $single = false )
    //Return: (mixed) Will be an array if $single is false. Will be value of meta data field if $single is true.
    //$product_id = get_post_meta($post_id, 'product_id', false );
    $product_ids = get_post_meta($post_id, 'product_id', false);
    if ($product_ids) {
        $meta_keys = ['_product_title', '_product_image_url', '_product_price', '_product_description'];
        //Delete all custom fields besides product_id to remove old data
        foreach ($meta_keys as $meta_key) {
            delete_post_meta($post_id, $meta_key);
        }
        foreach ($product_ids as $product_id) {
            $product_info = get_product_info($product_id, $meta_keys);
            foreach ($meta_keys as $meta_key) {
                //Function: add_post_meta($post_id, $meta_key, $meta_value, $unique);
                //@param: $post_id (integer) (required) The ID of the post to which a custom field should be added.
                //@param: $meta_key (string) (required) The key of the custom field which should be added.
                //@param $meta_value (mixed) (required) The value of the custom field which should be added. If an array is given, it will be serialized into a string.
                //@param $unique(boolean) (optional) Whether or not you want the key to stay unique. When set to true, the custom field will not be added if the given key already exists among custom fields of the specified post. Default: false
                //@return: On success, returns the ID of the inserted row, which validates to true. If the $unique argument was set to true and a custom field with the given key already exists, false is returned.
                add_post_meta($post_id, $meta_key, $product_info[$meta_key], false);
            }
        }
    } else {
        error_log("cta_product_scraper: get_post_meta() could not find a field with the 'product_id' name.");
    }
}
Beispiel #2
0
    if (check_product_sn_exist($product_sn, $product_id)) {
        make_json_error($_LANG['sys']['wrong'] . $_LANG['exist_same_product_sn']);
    }
    /* 修改 */
    $sql = "UPDATE " . $ecs->table('products') . " SET product_sn = '{$product_sn}' WHERE product_id = '{$product_id}'";
    $result = $db->query($sql);
    if ($result) {
        clear_cache_files();
        make_json_result($product_sn);
    }
} elseif ($_REQUEST['act'] == 'edit_product_number') {
    check_authz_json('goods_manage');
    $product_id = intval($_POST['id']);
    $product_number = intval($_POST['val']);
    /* 货品库存 */
    $product = get_product_info($product_id, 'product_number, goods_id');
    /* 修改货品库存 */
    $sql = "UPDATE " . $ecs->table('products') . " SET product_number = '{$product_number}' WHERE product_id = '{$product_id}'";
    $result = $db->query($sql);
    if ($result) {
        /* 修改商品库存 */
        if (update_goods_stock($product['goods_id'], $product_number - $product['product_number'])) {
            clear_cache_files();
            make_json_result($product_number);
        }
    }
} elseif ($_REQUEST['act'] == 'product_add_execute') {
    admin_priv('goods_manage');
    $product['goods_id'] = intval($_POST['goods_id']);
    $product['attr'] = $_POST['attr'];
    $product['product_sn'] = $_POST['product_sn'];
 private function _run()
 {
     G('begin');
     if (file_exists(WEB_ROOT . '/cron-0')) {
         return;
     } else {
         file_put_contents(WEB_ROOT . '/cron-0', 'cron-0');
     }
     /* 订单处理 */
     $Order = M('Order');
     $map = array('end_time' => array('elt', NOW_TIME), 'status' => array('in', '1,2,3'));
     $order_lsits = $Order->where($map)->select();
     foreach ($order_lsits as $key => $val) {
         $price = $val['price'] + $val['postage'];
         $product_name = get_product_info($val['product_id']);
         switch ($val['status']) {
             case '1':
                 //未付款
                 $parm = array('status' => 5, 'update_time' => $val['end_time'], 'desc' => '买家违约');
                 $data = array('first' => '你好,【' . $product_name . '】订单已经关闭,买家没有付款。', 'order_id' => $val['order_id'], 'order_status' => '已关闭(买家违约)', 'product_name' => $product_name, 'order_price' => $val['price'] + $val['postage'], 'end_time' => '违约时间:' . date('Y-m-d H:i:s', $val['end_time']));
                 break;
             case '2':
                 //未发货
                 $parm = array('status' => 5, 'update_time' => $val['end_time'], 'desc' => '卖家违约');
                 $data = array('first' => '你好,【' . $product_name . '】订单已经关闭,卖家没有发货,买家支付款将退还给买家', 'order_id' => $val['order_id'], 'order_status' => '已关闭(卖家违约)', 'product_name' => $product_name, 'order_price' => $price, 'end_time' => '违约时间:' . date('Y-m-d H:i:s', $val['end_time']));
                 // 退还买家支付款
                 fund_inc($val['user_id'], $price, '支付款退还');
                 break;
             case '3':
                 //系统自动签收
                 $parm = array('status' => 4, 'update_time' => $val['end_time'], 'desc' => '自动签收');
                 $data = array('first' => '你好,【' . $product_name . '】订单已经完成,系统自动签收。', 'order_id' => $val['order_id'], 'order_status' => '已完成(自动签收)', 'product_name' => $product_name, 'order_price' => $price, 'end_time' => '完成时间:' . date('Y-m-d H:i:s', $val['end_time']));
                 // 为商家充值
                 fund_inc($val['shop_id'], $price, '买卖交易');
                 break;
             default:
                 break;
         }
         // 更新订单状态
         $Order->where(array('order_id' => $val['order_id']))->save($parm);
         // 给卖家发
         $this->sendOrder(get_shop_info($val['shop_id'], 'openid'), U('Order/index', array('order_id' => $val['order_id'])), $data);
         // 给买家发
         $this->sendOrder(get_shop_info($val['user_id'], 'openid'), U('Order/index', array('order_id' => $val['order_id'])), $data);
     }
     /* 产品处理 */
     $Product = M('Product');
     $ProductBid = M('ProductBid');
     $map = array('status' => 1, 'end_time' => array('elt', NOW_TIME));
     $product_lists = $Product->where($map)->select();
     foreach ($product_lists as $key => $val) {
         switch ($val['product_type']) {
             case '1':
                 //普通
             //普通
             case '2':
                 //竞速
                 $bid_info = $ProductBid->where(array('product_id' => $val['product_id']))->order('bid_price desc')->find();
                 if ($bid_info) {
                     if ($bid_info['bid_price'] >= $val['reserve_price']) {
                         //改变状态
                         $result = $Product->where(array('product_id' => $val['product_id']))->setField('status', 2);
                         $count = $Order->where(array('product_id' => $val['product_id']))->count();
                         if ($result && empty($count)) {
                             // 下单
                             $order_id = create_order_id();
                             $end_time = strtotime('+2 day');
                             $data = array('order_id' => $order_id, 'shop_id' => $val['user_id'], 'user_id' => $bid_info['user_id'], 'product_id' => $val['product_id'], 'price' => $bid_info['bid_price'], 'postage' => $val['postage'], 'create_time' => NOW_TIME, 'update_time' => NOW_TIME, 'end_time' => $end_time, 'status' => 1);
                             M('Order')->add($data);
                             // 给卖家发
                             $data = array('first' => '你好,【' . $val['product_name'] . '】已经自动结拍,订单已经生成。', 'order_id' => $order_id, 'order_status' => '待支付(等待买家支付)', 'product_name' => $val['product_name'], 'order_price' => $bid_info['bid_price'] + $val['postage'], 'end_time' => '违约有效期:' . date('Y-m-d H:i:s', $end_time));
                             $this->sendOrder(get_shop_info($val['user_id'], 'openid'), U('Order/index', array('order_id' => $order_id)), $data);
                             // 给买家发
                             $data['first'] = '你好,【' . $val['product_name'] . '】已经自动结拍,订单已经生成,请在付款有效期内付款。';
                             $this->sendOrder(get_shop_info($bid_info['user_id'], 'openid'), U('Order/index', array('order_id' => $order_id)), $data);
                         }
                     } else {
                         // 给卖家发
                         $data = array('first' => '你好,【' . $val['product_name'] . '】已经流拍,出价没有高于或等于保留价。', 'product_id' => $val['product_id'], 'product_name' => $val['product_name'], 'remark' => '流拍时间:' . date('Y-m-d H:i:s', $val['end_time']));
                         $this->sendBid(get_shop_info($val['user_id'], 'openid'), U('Index/product', array('id' => $val['product_id'])), $data);
                         $Product->where(array('product_id' => $val['product_id']))->setField('status', 3);
                     }
                 } else {
                     // 给卖家发
                     $data = array('first' => '你好,【' . $val['product_name'] . '】已经流拍,没有人出价。', 'product_id' => $val['product_id'], 'product_name' => $val['product_name'], 'remark' => '流拍时间:' . date('Y-m-d H:i:s', $val['end_time']));
                     $this->sendBid(get_shop_info($val['user_id'], 'openid'), U('Index/product', array('id' => $val['product_id'])), $data);
                     $Product->where(array('product_id' => $val['product_id']))->setField('status', 3);
                 }
                 break;
             case '3':
                 //秒杀
                 $Product->where(array('product_id' => $val['product_id']))->setField('status', 2);
                 break;
             default:
                 # code...
                 break;
         }
     }
     /* 5分钟提示 */
     $map = array('product_type' => array('in', '1,2'), 'is_send' => 0, 'status' => 1, 'end_time' => array('elt', NOW_TIME + 300));
     $product_lists = $Product->where($map)->select();
     foreach ($product_lists as $value) {
         $Product->where(array('product_id' => $value['product_id']))->setField('is_send', 1);
         $bid_lists = $ProductBid->where(array('product_id' => $value['product_id']))->group('user_id')->select();
         $data = array('touser' => '', 'msgtype' => 'news', 'news' => array('articles' => array(array('title' => '5分钟结拍提示', 'description' => '你好,【' . $value['product_name'] . '】还有5分钟结束。' . $money . PHP_EOL . '结拍时间:' . date('Y-m-d H:i:s', $value['end_time']), 'url' => C('WEB_SITE_URL') . U('Index/product', array('id' => $value['product_id'])), 'picurl' => ''))));
         foreach ($bid_lists as $val) {
             $data['touser'] = get_shop_info($val['user_id'], 'openid');
             $this->WX->sendCustomMessage($data);
         }
     }
     /* 3分钟提示 */
     $map = array('product_type' => array('in', '1,2'), 'is_send' => 1, 'status' => 1, 'end_time' => array('elt', NOW_TIME + 180));
     $product_lists = $Product->where($map)->select();
     foreach ($product_lists as $value) {
         $Product->where(array('product_id' => $value['product_id']))->setField('is_send', 2);
         $bid_lists = $ProductBid->where(array('product_id' => $value['product_id']))->group('user_id')->select();
         $data = array('touser' => '', 'msgtype' => 'news', 'news' => array('articles' => array(array('title' => '3分钟结拍提示', 'description' => '你好,【' . $value['product_name'] . '】还有3分钟结束。' . $money . PHP_EOL . '结拍时间:' . date('Y-m-d H:i:s', $value['end_time']), 'url' => C('WEB_SITE_URL') . U('Index/product', array('id' => $value['product_id'])), 'picurl' => ''))));
         foreach ($bid_lists as $val) {
             $data['touser'] = get_shop_info($val['user_id'], 'openid');
             $this->WX->sendCustomMessage($data);
         }
     }
     /* 1分钟提示 */
     $map = array('product_type' => array('in', '1,2'), 'is_send' => 2, 'status' => 1, 'end_time' => array('elt', NOW_TIME + 60));
     $product_lists = $Product->where($map)->select();
     foreach ($product_lists as $value) {
         $Product->where(array('product_id' => $value['product_id']))->setField('is_send', 3);
         $bid_lists = $ProductBid->where(array('product_id' => $value['product_id']))->group('user_id')->select();
         $data = array('touser' => get_shop_info($val['user_id'], 'openid'), 'msgtype' => 'news', 'news' => array('articles' => array(array('title' => '1分钟结拍提示', 'description' => '你好,【' . $value['product_name'] . '】还有1分钟结束。' . $money . PHP_EOL . '结拍时间:' . date('Y-m-d H:i:s', $value['end_time']), 'url' => C('WEB_SITE_URL') . U('Index/product', array('id' => $value['product_id'])), 'picurl' => ''))));
         foreach ($bid_lists as $val) {
             $data['touser'] = get_shop_info($val['user_id'], 'openid');
             $this->WX->sendCustomMessage($data);
         }
     }
     G('end');
     @unlink(WEB_ROOT . '/cron-0');
     // file_put_contents(WEB_ROOT .'/cron-log.txt', date('Y-m-d H:i:s') . PHP_EOL . G('begin','end') . '0s' . PHP_EOL, FILE_APPEND);
 }
 public function user($status = 1)
 {
     if (IS_AJAX) {
         $page_size = 10;
         $page = I('page', 1, 'intval');
         $start = ($page - 1) * $page_size;
         $map = array('user_id' => $this->user_info['user_id'], 'status' => $status);
         $Order = M('Order');
         $total_count = $Order->where($map)->count();
         if ($total_count) {
             $total_page = ceil($total_count / $page_size);
             $order_list = $Order->where($map)->order('create_time desc')->limit($start . ',' . $page_size)->select();
             foreach ($order_list as $key => $value) {
                 $order_list[$key]['shop_info'] = get_shop_info($value['shop_id'], '');
                 $order_list[$key]['product_info'] = get_product_info($value['product_id'], '');
                 $order_list[$key]['z_price'] = $order_list[$key]['product_info']['postage'] + $value['price'];
             }
             $this->assign('order_list', $order_list);
             // print_r($order_list); exit;
             $content = $this->fetch('ajaxUser');
             $value = array('htmlString' => $content, 'isNextPage' => $total_page == 1 || $total_page == $page ? false : true, 'page' => $page, 'pageSize' => $page_size, 'totalCount' => $total_count, 'totalPage' => $total_page);
         } else {
             $value = array('htmlString' => '<div class="ui-section no-item" id="no-item">暂无数据</div>', 'isNextPage' => false, 'page' => $page, 'pageSize' => $page_size, 'totalCount' => $total_count, 'totalPage' => 1);
         }
         $this->resultSuccess('加载中...', $value);
     } else {
         $this->assign('status', $status);
         $this->display();
     }
 }
 if ($composition != -1) {
     $indications = wp_get_object_terms($composition, 'indication');
     $actions = wp_get_object_terms($composition, 'actions');
 }
 if ($composition != -1) {
     echo "<section class='column-7'>";
     echo "<h5>Composition</h5>";
     echo "<ul class='list composition-list'>";
     for ($i = 0; $i < count($composition); $i++) {
         $herburl = get_permalink($composition[$i]);
         echo "<li><a href='" . $herburl . "'>";
         $folk_name = get_post_meta($composition[$i], '_product_details_folk_name', true);
         if ($folk_name) {
             echo $folk_name . "<br>";
         }
         echo get_product_info($composition[$i]);
         echo "</a></li>";
     }
     echo "</ul>";
     echo "</section>";
 }
 if ($preparation) {
     echo "<section class='column-7'>";
     echo "<h5>Preparation</h5>";
     echo apply_filters('the_content', $preparation);
     echo "</section>";
 }
 if ($synthesis) {
     echo "<section class='column-7'>";
     echo "<h5>Synthesis and Mechanism of Action</h5>";
     echo apply_filters('the_content', $synthesis);
?>
			<div class="accordion">
				<?php 
//Composition list will be for bundled data (Professional Herbal Combination or Make your own compound Products)
if ($product->product_type == 'bundle') {
    $product_bundled_data = $product->bundle_data;
    if ($product_bundled_data && count($product_bundled_data) > 0) {
        ?>
					<div class="accordion-panel">
						<h5 class="accordion-panel-header">Composition List</h5>
						<div class="accordion-panel-content">
							<?php 
        $compositions = "";
        foreach ($product_bundled_data as $key => $value) {
            $id = $value['product_id'];
            $compositions[] = get_product_info($id);
        }
        echo implode(', ', $compositions);
        ?>
						</div>
					</div>
				<?php 
    }
}
//For Bundled Data
?>
				
				<?php 
$dosage = get_post_meta($post->ID, '_product_details_dosage', true);
?>
					<div class="accordion-panel">
 public function notify()
 {
     vendor('WxPayPubHelper.WxPayPubHelper');
     //使用通用通知接口
     $notify = new \Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
     //以log文件形式记录回调信息
     //         $log_ = new Log_();
     $log_name = 'Public/notify_url.log';
     //log文件路径
     log_result($log_name, "【接收到的notify通知】:\n" . $xml . "\n");
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             log_result($log_name, "【通信出错】:\n" . $xml . "\n");
         } elseif ($notify->data["result_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             log_result($log_name, "【业务出错】:\n" . $xml . "\n");
         } else {
             //此处应该更新一下订单状态,商户自行增删操作
             log_result($log_name, "【支付成功】:\n" . $xml . "\n");
             list($order_id) = explode('_', $notify->data['out_trade_no']);
             $order_info = M('Order')->where(array('order_id' => $order_id))->find();
             $order_info['product_name'] = get_product_info($order_info['product_id']);
             if ($order_info && $order_info['status'] == 1) {
                 $options = array('appid' => \WxPayConf_pub::APPID, 'appsecret' => \WxPayConf_pub::APPSECRET);
                 $WX = new \Vendor\TPWechat($options);
                 // 给客户发
                 $end_time = strtotime('+3 day');
                 $temp = array('touser' => get_shop_info($order_info['user_id'], 'openid'), 'template_id' => 'hIPbD2pnKDr-oUt5LdR3tFlAn2WaFdLi8KTRzSrvgH0', 'url' => \WxPayConf_pub::JS_API_CALL_URL . U('Order/index', array('order_id' => $order_id)), 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => '你好,【' . $order_info['product_name'] . '】订单已经完成支付'), 'keyword1' => array('value' => $order_info['order_id']), 'keyword2' => array('value' => '支付成功(等待卖家发货)', 'color' => '#FF0000'), 'keyword3' => array('value' => $order_info['product_name']), 'remark' => array('value' => '违约有效期:' . date('Y-m-d H:i:s', $end_time))));
                 $WX->sendTemplateMessage($temp);
                 // 给商家发
                 $temp['touser'] = get_shop_info($order_info['shop_id'], 'openid');
                 $temp['data']['first']['value'] = '你好,【' . $order_info['product_name'] . '】订单已经完成支付,请尽快发货';
                 $WX->sendTemplateMessage($temp);
                 // 更新支付状态
                 $data = array('status' => 2, 'update_time' => NOW_TIME, 'end_time' => $end_time);
                 M('Order')->where(array('order_id' => $order_info['order_id']))->save($data);
                 $data = array('action' => 1, 'order_id' => $notify->data['out_trade_no'], 'fee' => $notify->data['total_fee'], 'time' => NOW_TIME);
                 M('Pay_log')->add($data);
             }
         }
         //商户自行增加处理流程,
         //例如:更新订单状态
         //例如:数据库操作
         //例如:推送支付完成信息
     }
 }
Beispiel #8
0
#!/usr/bin/php
<?php 
require_once 'functions.php';
//提取关键信息的主程序,利用linux的shell实现多线程
$product_id = (int) $argv[1];
$flag = (int) $argv[2];
get_product_info($product_id);