toData('1', '分页参数错误'); } $where = []; $userId = 0; // 用户号精确搜索 if (!empty($param['user_no'])) { $user = UserModel::where('user_no', $param['user_no'])->find(); if (empty($user)) { return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => StockMarketModel::STOCK_MARKET_TYPE]); } $userId = $user['user_id']; } // 判断是否是代理 如果是代理 只能看他自己管理的用户 $whereU = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); if (!is_array($whereU)) { return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => StockMarketModel::STOCK_MARKET_TYPE]); } // 股票号 if (!empty($param['stock_code']) && is_string($param['stock_code'])) { $where[] = [ 'stock_code', 'like', '%' . $param['stock_code'] ]; } $tableObj = (new IPOService())->getStockModel($marketType); $query = Db::table($tableObj['give_order_table'])->where($where)->where($whereU)->with(['user' => function ($query) { $query->field('user_id,user_no,nick_name,email,phone_number'); }])->order('id', 'desc'); $totalQuery = Db::table($tableObj['give_order_table'])->where($where)->where($whereU)->order('id', 'desc'); $list = $query->page($param['page'], $param['limit'])->select()->toArray(); $total = $totalQuery->count(); $stockCodeArr = array_column($list, 'stock_code'); $stockNameArr = Db::table($tableObj['list_table'])->whereIn('stock_code', $stockCodeArr)->column('stock_name', 'stock_code'); foreach ($list as &$v) { $v['stock_name'] = $stockNameArr[$v['stock_code']]; } return $this->toData('0', 'SUCCESS', ['list' => $list, 'total' => $total, 'extent' => StockMarketModel::STOCK_MARKET_TYPE]); } catch (\Exception $exception) { return $this->toData('1', '系统繁忙', [$exception->getMessage()]); } } // 新增 public function add($marketType, $param) { try { // 股票代码 if (empty($param['stock_code']) || !is_string($param['stock_code'])) { return $this->toData('1', '股票代码 无效'); } if (empty($param['tape']) || !is_numeric($param['tape'])) { return $this->toData('1', '交易所 无效'); } $tapeList = (new StockMarketModel)->getAllTape(); if (strpos($param['stock_code'], ':') !== false) { $param['stock_code'] = explode(':', $param['stock_code'])[1]; } $tape = $tapeList[$marketType][$param['tape']]; if ($marketType != 3) $param['stock_code'] = $tape . ':' . $param['stock_code']; $tableObj = (new IPOService())->getStockModel($marketType); $isHas = Db::table($tableObj['list_table'])->where('stock_code', $param['stock_code'])->value('id'); if (empty($isHas)) return $this->toData('1', '股票 无效'); // 股票代码 if (empty($param['user_id']) || !is_numeric($param['user_id'])) { return $this->toData('1', '用户 无效'); } if (empty($param['num']) || !is_numeric($param['num']) || $param['num'] <= 0) { return $this->toData('1', '送股数量 无效'); } $price=!empty($param['price']) ? floatval($param['price']) : 0; $date = date('Y-m-d H:i:s'); $orderNo = (new Tool())->orderNo(20); $insertArr = [ 'user_id' => $param['user_id'], 'stock_code' => $param['stock_code'], 'order_no' => $orderNo, 'num' => $param['num'], 'price' => $price, 'amount' => $price*$param['num'], 'create_time' => $date, 'update_time' => $date ]; $insertBool = Db::table($tableObj['give_order_table'])->insert($insertArr); if ($insertBool) { // 通知交易 $bool = (new ClientGo())->giveawaysStock($param['stock_code'], $orderNo, $param['market_type']); if (!$bool) { return $this->toData('1', '给交易推送数据异常', []); } } return $this->toData('0', 'SUCCESS'); } catch (\Exception $exception) { return $this->toData('0', '系统繁忙', [$exception->getMessage()]); } } }