/** * AJAX统计金额 */ public function getAmount() { if (IS_AJAX) { $vip = vip_level($this->mid); $goods_o_price = intval($_POST['goods_o_price'] * 100) / 100; $goods_storage = intval($_POST['goods_storage']); $goods_price = intval($_POST['goods_price'] * 100) / 100; $goods_min_num = intval($_POST['goods_min_num']); $amount = $goods_o_price * $goods_min_num * $goods_storage + $goods_price * $goods_storage; $top = intval($_POST['top']); if ($vip == 0 && $top) { $amount += 10; } $option = $_POST['option']; if (!empty($option)) { if ($vip) { $field = 'vip_price'; } else { $field = 'price'; } if (is_array($option)) { foreach ($option as $key => $val) { $amount += M('MoreOption')->where(array('id' => $val, 'status' => 1))->getField($field) * $goods_storage; } } } echo $amount; } }
/** * 浏览收藏任务 */ public function browse() { if (IS_POST) { //计算所需价格 $vip = vip_level($this->mid); $goods_o_price = intval($_POST['goods_o_price'] * 100) / 100; $tax_rate = MSC('tax_rate'); $goods_storage = intval($_POST['goods_storage']); $freight = intval($_POST['freight'] * 100) / 100; $goods_min_num = intval($_POST['goods_min_num']); $goods_price = ($goods_o_price * $goods_min_num + $freight) * $tax_rate; $add_bounty = intval($_POST['add_bounty'] * 100) / 100; $amount = ($goods_o_price * $goods_min_num + $freight) * $goods_storage + $goods_price * $goods_storage + $add_bounty * $goods_storage; $option = $_POST['vip_select']; //vip服务 if (intval($_POST['vip_service'])) { $data['limit_id'] = intval($_POST['limit_id']); if (!empty($option)) { $vip_discount = get_vip_discount($vip); if (is_array($option)) { foreach ($option as $key => $val) { $amount += M('VipOption')->where(array('option_id' => $val))->getField('option_price') * $goods_storage * $vip_discount; } } } if (intval($_POST['limit_id'])) { $amount += M('GoodsLimit')->where(array('limit_id' => intval($_POST['limit_id']), 'status' => 1))->getField('price'); } $data['add_comment'] = str_rp(trim($_POST['add_comment'])); } //计划任务 if (intval($_POST['plan']) && intval($_POST['plan_days']) && intval($_POST['plan_publish_num']) && intval($_POST['interval_time'])) { $plan_click = intval($_POST['plan_days']) * intval($_POST['plan_publish_num']); $amount += $plan_click * MSC('plan_cost'); } //保存主图 if (!empty($_POST['pic'])) { $data['goods_pic'] = $_POST['pic'][0]; } //数据整合处理 $data['seller_id'] = $this->mid; $data['goods_name'] = str_rp(trim($_POST['goods_name'])); $data['goods_url'] = str_rp(trim($_POST['goods_url'])); $data['goods_o_price'] = $goods_o_price; $data['goods_storage'] = $goods_storage; $data['goods_price'] = $goods_price; //$data['goods_price'] = $goods_price*(1-(MSC('website_bonus')/100)); $data['goods_min_num'] = $goods_min_num; $data['freight'] = $freight; $data['goods_amount'] = $amount; $data['add_bounty'] = $add_bounty; $data['search_key'] = str_rp(trim($_POST['search_key'])); $data['search_tip'] = str_rp(trim($_POST['search_tip'])); $data['comment'] = str_rp(trim($_POST['comment'])); $data['pf_id'] = intval($_POST['web_platform']); $data['web_platform'] = M('Platform')->where(array('pf_id' => $data['pf_id']))->getField('pf_name'); $data['account_id'] = M('SellerAccount')->where(array('account_id' => intval($_POST['account_id']), 'seller_id' => $this->mid, 'status' => 1))->getField('account_id'); $data['goods_type_id'] = 4; $data['pay_result'] = 10; $data['goods_status'] = 1; $data['add_time'] = NOW_TIME; $data['has_word'] = $_POST['zi']; $device_id = intval($_POST['device_id']); if ($device_id == 1) { $data['goods_device'] = '手机'; } elseif ($device_id == 2) { $data['goods_device'] = '电脑'; } //保存模板 if (intval($_POST['save_temp'])) { $data['temp_name'] = str_rp(trim($_POST['temp_name'])); } $res = $this->model->add($data); if ($res) { //图片保存(上传) if (!empty($_POST['pic'])) { foreach ($_POST['pic'] as $key => $val) { $pic[$key]['goods_id'] = $res; $pic[$key]['pic'] = $val; $pic[$key]['p_sort'] = 0; } $gpr = M('GoodsPic')->addAll($pic); } //计划任务 if (intval($_POST['plan']) && intval($_POST['plan_days']) && intval($_POST['plan_publish_num']) && intval($_POST['interval_time'])) { $plan_data['goods_id'] = $res; $plan_data['plan_days'] = intval($_POST['plan_days']); $plan_data['plan_publish_num'] = intval($_POST['plan_publish_num']); $plan_data['plan_interval'] = intval($_POST['interval_time']) * 60; $plan_data['plan_days_start'] = intval($_POST['hours']) * 60 * 60 + intval($_POST['minute']) * 60; $rpd = M('PublishPlan')->add($plan_data); } //vip if (!empty($option)) { if (is_array($option)) { foreach ($option as $key => $val) { $option_data['goods_id'] = $res; $option_data['option_id'] = $val; M('GoodsOption')->add($option_data); } } } $predeposit = M('Seller')->where(array('seller_id' => $this->mid))->getField('predeposit'); if ($predeposit < $amount) { $this->error('预存款不足,请进行充值', U('Member/recharge', array('price' => $amount - $predeposit))); } else { $pay['predeposit'] = $predeposit - $amount; $frozen = M('Seller')->where(array('seller_id' => $this->mid))->getField('frozen'); $pay['frozen'] = $frozen + $amount; $result = M('Seller')->where(array('seller' => $this->mid))->save($pay); $this->model->where(array('goods_id' => $res, 'seller_id' => $this->mid))->setInc('frozen_amount', $amount); if ($result) { $crs = $this->model->where(array('goods_id' => $res, 'seller_id' => $this->mid))->setField('pay_result', 20); //生成账单日志 $data['order_sn'] = 'S2_' . order_sn(); $data['seller_id'] = $this->mid; $data['buyer_name'] = get_seller_nickname($data['seller_id']); $data['order_type'] = 2; $data['payment_id'] = 0; $data['payment_name'] = '预存款转入冻结款'; $data['payment_time'] = NOW_TIME; $data['shipping_express_id'] = 0; $data['goods_amount'] = price_format($amount); $data['order_title'] = '任务id:' . $res . '冻结' . $data['goods_amount'] . '金币'; $data['discount'] = 0; $data['order_amount'] = $data['goods_amount'] - $data['discount']; $data['order_state'] = 10; $data['add_time'] = NOW_TIME; $rc = $this->orderModel->add($data); if ($crs) { $bill_data['seller_id'] = $this->mid; $bill_data['bill_log'] = '发布浏览收藏任务,任务号:' . $res . '冻结' . $amount; $bill_data['amount'] = $amount; $bill_data['balance'] = $pay['predeposit']; $bill_data['addtime'] = NOW_TIME; $bill_data['bill_type'] = -2; //冻结 M('SellerBill')->add($bill_data); } } $this->success('发布任务成功'); } } else { $this->error('发布任务失败'); } } elseif (IS_GET) { $where['select_status'] = 1; $vip_option = $this->vipOptionModel->relation(true)->where($where)->order($this->order)->select(); $platform = M('Platform')->order('pf_sort desc')->select(); $map['temp_name'] = array('neq', ''); $map['seller_id'] = $this->mid; $template = $this->model->where($map)->order('add_time desc')->select(); $this->assign('template', $template); $this->assign('platform', $platform); $this->assign('vip_option', $vip_option); $this->h3_title = '浏览收藏任务'; $this->display('publish'); } }