MSupplierOfferPriceSheet.Class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <?php
  2. namespace JinDouYun\Model\Price;
  3. use JinDouYun\Controller\Common\Logger;
  4. use JinDouYun\Dao\Price\DSupplierOfferPriceSheet;
  5. use JinDouYun\Dao\Price\DSupplierOfferPriceSheetDetails;
  6. use JinDouYun\Model\Goods\MGoods;
  7. use JinDouYun\Model\GoodsManage\MGoodsBasic;
  8. use JinDouYun\Model\GoodsManage\MSku;
  9. use JinDouYun\Model\Purchase\MSupplier;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\ResultWrapper;
  12. use Mall\Framework\Core\StatusCode;
  13. /**
  14. * @copyright Copyright (c) https://www.qianniaovip.com All rights reserved
  15. * Description: 供应商报价单Model
  16. * Class MSupplierOfferPriceSheet
  17. * @package JinDouYun\Model\Price
  18. */
  19. class MSupplierOfferPriceSheet
  20. {
  21. /**
  22. * @var DSupplierOfferPriceSheet
  23. */
  24. private $objDSupplierOfferPriceSheet;
  25. /**
  26. * @var DSupplierOfferPriceSheetDetails
  27. */
  28. private $objDSupplierOfferPriceSheetDetails;
  29. /**
  30. * @var int
  31. */
  32. private $onlineUserId;
  33. /**
  34. * @var int
  35. */
  36. private $onlineEnterpriseId;
  37. /**
  38. * MSupplierOfferPriceSheet constructor.
  39. * @param $onlineUserId
  40. * @param $onlineEnterpriseId
  41. * @throws \Exception
  42. */
  43. public function __construct($onlineUserId, $onlineEnterpriseId)
  44. {
  45. $this->onlineUserId = $onlineUserId;
  46. $this->onlineEnterpriseId = $onlineEnterpriseId;
  47. $this->objDSupplierOfferPriceSheet = new DSupplierOfferPriceSheet();
  48. $this->objDSupplierOfferPriceSheetDetails = new DSupplierOfferPriceSheetDetails();
  49. $this->objDSupplierOfferPriceSheet->setTable('qianniao_supplierOfferPrice_sheet_' . $this->onlineEnterpriseId);
  50. $this->objDSupplierOfferPriceSheetDetails->setTable('qianniao_supplierOfferPrice_sheet_details_' . $this->onlineEnterpriseId);
  51. }
  52. /**
  53. * Doc: (des="添加供应商报价单")
  54. * User: XMing
  55. * Date: 2020/12/16
  56. * Time: 6:10 下午
  57. * @param array $params
  58. * @param int $supplierId
  59. * @return ResultWrapper
  60. * @throws \Exception
  61. */
  62. public function add(array $params, int $supplierId): ResultWrapper
  63. {
  64. $details = getArrayItem($params, 'details', []);
  65. if (empty($details)) {
  66. return ResultWrapper::fail('报价单商品数据为空', ErrorCode::$paramError);
  67. }
  68. $objMSupplier = new MSupplier($this->onlineUserId, $this->onlineEnterpriseId);
  69. $supplierResult = $objMSupplier->getSupplierById($supplierId);
  70. if (!$supplierResult->isSuccess()) {
  71. return ResultWrapper::fail($supplierResult->getData(), $supplierResult->getErrorCode());
  72. }
  73. $supplier = $supplierResult->getData();
  74. $params['supplierName'] = getArrayItem($supplier, 'title', '');
  75. $params['userId'] = $this->onlineUserId;
  76. $sheetInsert = self::buildSupplierOfferPriceSheetData($params);
  77. $this->objDSupplierOfferPriceSheet->beginTransaction();
  78. $sheetId = $this->objDSupplierOfferPriceSheet->insert($sheetInsert);
  79. if ($sheetId === false) {
  80. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheet->error());
  81. $this->objDSupplierOfferPriceSheet->rollBack();
  82. return ResultWrapper::fail($this->objDSupplierOfferPriceSheet->error(), ErrorCode::$dberror);
  83. }
  84. $sheetDetailsInserts = [];
  85. foreach ($details as $detail) {
  86. $detail['linkId'] = $sheetId;
  87. $sheetDetailsInserts[] = self::buildSupplierOfferPriceSheetDetailsData($detail, $supplierId);
  88. }
  89. $dbResult = $this->objDSupplierOfferPriceSheetDetails->insert($sheetDetailsInserts, true);
  90. if ($dbResult === false) {
  91. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheetDetails->error());
  92. $this->objDSupplierOfferPriceSheet->rollBack();
  93. return ResultWrapper::fail($this->objDSupplierOfferPriceSheetDetails->error(), ErrorCode::$dberror);
  94. }
  95. $this->objDSupplierOfferPriceSheet->commit();
  96. return ResultWrapper::success($sheetId);
  97. }
  98. /**
  99. * Doc: (des="编辑报价单")
  100. * User: XMing
  101. * Date: 2020/12/17
  102. * Time: 11:53 上午
  103. * @param array $params
  104. * @param int $id
  105. * @param int $supplierId
  106. * @return ResultWrapper
  107. */
  108. public function edit(array $params, int $id, int $supplierId): ResultWrapper
  109. {
  110. $details = getArrayItem($params, 'details', []);
  111. if (empty($details)) {
  112. return ResultWrapper::fail('报价单商品数据为空', ErrorCode::$paramError);
  113. }
  114. $commonResult = self::commonMerge($details, $id, $supplierId);
  115. if (!$commonResult->isSuccess()) {
  116. Logger::logs(E_USER_ERROR, 'error', __CLASS__, __LINE__, $commonResult->getData());
  117. return ResultWrapper::fail($commonResult->getData(), $commonResult->getErrorCode());
  118. }
  119. $commonMerge = $commonResult->getData();
  120. $this->objDSupplierOfferPriceSheet->beginTransaction();
  121. $updateResult = $this->objDSupplierOfferPriceSheet->update(['updateTime' => time()], $id);
  122. if ($updateResult === false) {
  123. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheet->error());
  124. $this->objDSupplierOfferPriceSheet->rollBack();
  125. return ResultWrapper::fail($this->objDSupplierOfferPriceSheet->error(), ErrorCode::$dberror);
  126. }
  127. $insert = getArrayItem($commonMerge, 'insert', []);
  128. $update = getArrayItem($commonMerge, 'update', []);
  129. $delete = getArrayItem($commonMerge, 'delete', []);
  130. if (!empty($insert)) {
  131. $result = $this->objDSupplierOfferPriceSheetDetails->insert($insert, true);
  132. if ($result === false) {
  133. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheetDetails->error());
  134. $this->objDSupplierOfferPriceSheet->rollBack();
  135. return ResultWrapper::fail($this->objDSupplierOfferPriceSheetDetails->error(), ErrorCode::$dberror);
  136. }
  137. }
  138. if (!empty($delete)) {
  139. $result = $this->objDSupplierOfferPriceSheetDetails
  140. ->update(['deleteStatus' => StatusCode::$delete, 'updateTime' => time()], ['id' => $delete]);
  141. if ($result === false) {
  142. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheetDetails->error());
  143. $this->objDSupplierOfferPriceSheet->rollBack();
  144. return ResultWrapper::fail($this->objDSupplierOfferPriceSheetDetails->error(), ErrorCode::$dberror);
  145. }
  146. }
  147. if (!empty($update)) {
  148. foreach ($update as $value) {
  149. $result = $this->objDSupplierOfferPriceSheetDetails
  150. ->update(['updateTime' => time(), 'offerPrice' => $value['offerPrice']], $value['id']);
  151. if ($result === false) {
  152. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheetDetails->error());
  153. $this->objDSupplierOfferPriceSheet->rollBack();
  154. return ResultWrapper::fail($this->objDSupplierOfferPriceSheetDetails->error(), ErrorCode::$dberror);
  155. }
  156. }
  157. }
  158. $this->objDSupplierOfferPriceSheet->commit();
  159. return ResultWrapper::success(true);
  160. }
  161. /**
  162. * Doc: (des="列表")
  163. * User: XMing
  164. * Date: 2020/12/17
  165. * Time: 10:26 上午
  166. * @param array $selectParams
  167. * @return ResultWrapper
  168. */
  169. public function getAll(array $selectParams): ResultWrapper
  170. {
  171. $buildSql = self::buildSqlBySelectParams($selectParams);
  172. $lists = $this->objDSupplierOfferPriceSheet->query($buildSql['sql']);
  173. if ($lists === false) {
  174. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheet->error());
  175. return ResultWrapper::fail($this->objDSupplierOfferPriceSheet->error(), ErrorCode::$dberror);
  176. }
  177. $count = $this->objDSupplierOfferPriceSheet->query($buildSql['countSql']);
  178. self::formatSheetLists($lists);
  179. $ret = [
  180. 'data' => $lists,
  181. 'total' => isset($count[0]['total']) ? $count[0]['total'] : 0,
  182. ];
  183. return ResultWrapper::success($ret);
  184. }
  185. /**
  186. * Doc: (des="详情")
  187. * User: XMing
  188. * Date: 2020/12/17
  189. * Time: 10:53 上午
  190. * @param int $id
  191. * @return ResultWrapper
  192. * @throws \Exception
  193. */
  194. public function get(int $id): ResultWrapper
  195. {
  196. $result = $this->objDSupplierOfferPriceSheet->get($id);
  197. if ($result === false) {
  198. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheet->error());
  199. return ResultWrapper::fail($this->objDSupplierOfferPriceSheet->error(), ErrorCode::$dberror);
  200. }
  201. if (empty($result)) {
  202. return ResultWrapper::fail('未获取到指定单据信息', ErrorCode::$paramError);
  203. }
  204. $detailsResult = self::getSheetDetailsByLinkId($result['id']);
  205. if (!$detailsResult->isSuccess()) {
  206. Logger::logs(E_USER_ERROR, 'error', __CLASS__, __LINE__, $detailsResult->getData());
  207. return ResultWrapper::fail($detailsResult->getData(), $detailsResult->getErrorCode());
  208. }
  209. $result['no'] = StatusCode::$noPrefix[StatusCode::$orderType['supplierOfferPrice']] . $result['no'];
  210. $result['details'] = $detailsResult->getData();
  211. return ResultWrapper::success($result);
  212. }
  213. /**
  214. * Doc: (des="")
  215. * User: XMing
  216. * Date: 2020/12/17
  217. * Time: 11:57 上午
  218. * @param array $params
  219. * @param int $linkId
  220. * @param int $supplierId
  221. * @return ResultWrapper
  222. */
  223. private function commonMerge(array $params, int $linkId, int $supplierId): ResultWrapper
  224. {
  225. $lists = $this->objDSupplierOfferPriceSheetDetails->select(['linkId' => $linkId, 'deleteStatus' => StatusCode::$standard]);
  226. if ($lists === false) {
  227. return ResultWrapper::fail($this->objDSupplierOfferPriceSheetDetails->error(), ErrorCode::$dberror);
  228. }
  229. $oldMaterielIdIds = [];
  230. $oldMaterielIdMap = [];
  231. foreach ($lists as $list) {
  232. $oldMaterielIdIds[] = $list['materielId'];
  233. $oldMaterielIdMap[$list['materielId']] = $list;
  234. }
  235. $update = [];
  236. $insert = [];
  237. $delete = [];
  238. foreach ($params as $param) {
  239. if (in_array($param['materielId'], $oldMaterielIdIds)) {
  240. $id = $oldMaterielIdMap[$param['materielId']]['id'];
  241. if (empty($id)) {
  242. return ResultWrapper::fail('id参数异常', ErrorCode::$paramError);
  243. }
  244. $update[] = [
  245. 'offerPrice' => json_encode($param['offerPrice']),
  246. 'id' => $id,
  247. ];
  248. unset($oldMaterielIdMap[$param['materielId']]);
  249. continue;
  250. }
  251. $param['linkId'] = $linkId;
  252. $insert[] = self::buildSupplierOfferPriceSheetDetailsData($param, $supplierId);
  253. }
  254. foreach ($oldMaterielIdMap as $value) {
  255. $delete[] = $value['id'];
  256. }
  257. $ret = [
  258. 'insert' => $insert,
  259. 'update' => $update,
  260. 'delete' => $delete
  261. ];
  262. return ResultWrapper::success($ret);
  263. }
  264. /**
  265. * Doc: (des="删除")
  266. * User: XMing
  267. * Date: 2020/12/17
  268. * Time: 11:45 上午
  269. * @param int $id
  270. * @return ResultWrapper
  271. */
  272. public function del(int $id): ResultWrapper
  273. {
  274. $dbResult = $this->objDSupplierOfferPriceSheet->update(['deleteStatus' => StatusCode::$delete, 'updateTime' => time()], $id);
  275. if ($dbResult === false) {
  276. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheet->error());
  277. return ResultWrapper::fail($this->objDSupplierOfferPriceSheet->error(), ErrorCode::$dberror);
  278. }
  279. return ResultWrapper::success(true);
  280. }
  281. /**
  282. * Doc: (des="根据linkId获取详情睡")
  283. * User: XMing
  284. * Date: 2020/12/17
  285. * Time: 11:00 上午
  286. * @param int $linkId
  287. * @return ResultWrapper
  288. * @throws \Exception
  289. */
  290. protected function getSheetDetailsByLinkId(int $linkId): ResultWrapper
  291. {
  292. $lists = $this->objDSupplierOfferPriceSheetDetails->select(['linkId' => $linkId, 'deleteStatus' => StatusCode::$standard]);
  293. if ($lists === false) {
  294. return ResultWrapper::fail($this->objDSupplierOfferPriceSheetDetails->error(), ErrorCode::$dberror);
  295. }
  296. $formatResult = self::formatSheetDetails($lists);
  297. if (!$formatResult->isSuccess()) {
  298. return ResultWrapper::fail($formatResult->getData(), $formatResult->getErrorCode());
  299. }
  300. $format = $formatResult->getData();
  301. return ResultWrapper::success($format);
  302. }
  303. /**
  304. * Doc: (des="格式化报价单详情数据")
  305. * User: XMing
  306. * Date: 2020/12/17
  307. * Time: 11:03 上午
  308. * @param array $lists
  309. * @return ResultWrapper
  310. * @throws \Exception
  311. */
  312. protected function formatSheetDetails(array $lists): ResultWrapper
  313. {
  314. if (empty($lists)) {
  315. return ResultWrapper::success([]);
  316. }
  317. $materielIds = [];
  318. foreach ($lists as $list) {
  319. $materielIds[] = $list['materielId'];
  320. }
  321. $objMGoodsBasic = new MGoodsBasic( $this->onlineUserId,$this->onlineEnterpriseId);
  322. $materielMapResult = $objMGoodsBasic->getMapsByIds($materielIds);
  323. if (!$materielMapResult->isSuccess()) {
  324. return ResultWrapper::fail($materielMapResult->getData(), $materielMapResult->getErrorCode());
  325. }
  326. $materielMap = $materielMapResult->getData();
  327. if (empty($materielMap)) {
  328. return ResultWrapper::fail('未获取到物料数据', ErrorCode::$paramError);
  329. }
  330. $skuIds = [];
  331. foreach ($lists as &$list) {
  332. $row = getArrayItem($materielMap, $list['materielId'], []);
  333. $list['materielName'] = '';
  334. $list['materielImages'] = [];
  335. $list['materielCode'] = '';
  336. if (!empty($row)) {
  337. $list['materielName'] = getArrayItem($row, 'title', '');
  338. $list['materielImages'] = getArrayItem($row, 'images', []);
  339. $list['materielCode'] = getArrayItem($row, 'code', []);
  340. }
  341. $list['offerPrice'] = json_decode($list['offerPrice'], true);
  342. foreach ($list['offerPrice'] as $skuId => $value){
  343. !empty($skuId) && $skuIds[] = $skuId;
  344. }
  345. }
  346. unset($list);
  347. $objMSku = new MSku($this->onlineUserId,$this->onlineEnterpriseId);
  348. $skuMapResult = $objMSku->getSkuMapByIds($skuIds);
  349. if (!$skuMapResult->isSuccess()){
  350. return ResultWrapper::fail($skuMapResult->getData(), $skuMapResult->getErrorCode());
  351. }
  352. $skuMap = $skuMapResult->getData();
  353. foreach ($lists as &$list){
  354. $offerPrice = getArrayItem($list,'offerPrice',[]);
  355. foreach ($offerPrice as $skuId => &$value){
  356. $skuRow = getArrayItem($skuMap,$skuId,[]);
  357. if (!empty($skuRow)){
  358. $value['unitName'] = getArrayItem($skuRow,'unitName','');
  359. $value['specGroup'] = getArrayItem($skuRow,'specGroup',[]);
  360. }
  361. }
  362. $list['offerPrice'] = $offerPrice;
  363. }
  364. return ResultWrapper::success($lists);
  365. }
  366. /**
  367. * Doc: (des="格式化报价单列表")
  368. * User: XMing
  369. * Date: 2020/12/17
  370. * Time: 10:52 上午
  371. * @param $lists
  372. */
  373. protected static function formatSheetLists(&$lists)
  374. {
  375. foreach ($lists as &$list) {
  376. $list['no'] = StatusCode::$noPrefix[StatusCode::$orderType['supplierOfferPrice']] . $list['no'];
  377. }
  378. }
  379. /**
  380. * Doc: (des="构建sql")
  381. * User: XMing
  382. * Date: 2020/12/17
  383. * Time: 10:27 上午
  384. * @param array $selectParams
  385. * @return array
  386. */
  387. private function buildSqlBySelectParams(array $selectParams): array
  388. {
  389. $tableName = $this->objDSupplierOfferPriceSheet->get_Table();
  390. $fields = ' * ';
  391. $countFields = ' COUNT(`id`) AS total ';
  392. $whereSql = '';
  393. if (isset($selectParams['supplierId']) && !empty($selectParams['supplierId'])) {
  394. $whereSql .= ' AND `supplierId` = ' . $selectParams['supplierId'];
  395. }
  396. if (isset($selectParams['auditStatus']) && !empty($selectParams['auditStatus'])){
  397. $whereSql .= ' AND `auditStatus` = ' . $selectParams['auditStatus'];
  398. }
  399. if (isset($selectParams['keyword']) && !empty($selectParams['keyword'])) {
  400. $keyword = '"%' . $selectParams['keyword'] . '%"';
  401. $whereSql .= ' AND ( `no` LIKE ' . $keyword . ' OR `supplierName` LIKE ' . $keyword . ') ';
  402. }
  403. if (isset($selectParams['startTime']) && !empty($selectParams['startTime'])) {
  404. $whereSql .= ' AND `createTime` BETWEEN ' . $selectParams['startTime'] . ' AND ' . $selectParams['endTime'];
  405. }
  406. $countSql = 'SELECT ' . $countFields . ' FROM ' . $tableName . ' WHERE `deleteStatus` = ' . StatusCode::$standard . $whereSql;
  407. $whereSql .= ' ORDER BY createTime DESC ';
  408. if (isset($selectParams['limit']) && !empty($selectParams['limit'])) {
  409. $whereSql .= ' LIMIT ' . $selectParams['offset'] . ',' . $selectParams['limit'];
  410. }
  411. $sql = 'SELECT ' . $fields . ' FROM ' . $tableName . ' WHERE `deleteStatus` = ' . StatusCode::$standard . $whereSql;
  412. return [
  413. 'sql' => $sql,
  414. 'countSql' => $countSql
  415. ];
  416. }
  417. /**
  418. * Doc: (des="构建供应商报价单数据")
  419. * User: XMing
  420. * Date: 2020/12/16
  421. * Time: 5:54 下午
  422. * @param array $params
  423. * @return array
  424. */
  425. public static function buildSupplierOfferPriceSheetData(array $params): array
  426. {
  427. $no = createOrderSn(StatusCode::$source['manage'], StatusCode::$orderType['supplierOfferPrice'], $params['userId']);
  428. return [
  429. 'no' => getArrayItem($params, 'no', $no),
  430. // char(25) NOT NULL COMMENT '订单编号',
  431. 'supplierId' => getArrayItem($params, 'supplierId', 0),
  432. // int(10) DEFAULT '0' COMMENT '供应商id',
  433. 'supplierName' => getArrayItem($params, 'supplierName', ''),
  434. // varchar(50) DEFAULT '1,2' COMMENT '供应商名称',
  435. 'materielNum' => getArrayItem($params, 'materielNum', 0),
  436. // int(10) NOT NULL DEFAULT '0' COMMENT '物料数量',
  437. 'auditStatus' => getArrayItem($params, 'auditStatus', StatusCode::$auditStatus['auditing']),
  438. // tinyint(3) DEFAULT '2' COMMENT '审核状态 默认1 待审 2审核通过 3 审核未通过 4 审核中',
  439. 'deleteStatus' => StatusCode::$standard,
  440. // tinyint(3) NOT NULL DEFAULT '5' COMMENT '是否删除 4 删除 5正常',
  441. 'createTime' => getArrayItem($params, 'createTime', time()),
  442. // int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
  443. 'updateTime' => getArrayItem($params, 'updateTime', time()),
  444. // int(10) NOT NULL DEFAULT '0' COMMENT '更新时间',
  445. 'extends' => getArrayItem($params, 'extends', null),
  446. // json DEFAULT NULL COMMENT '拓展字段',
  447. ];
  448. }
  449. /**
  450. * Doc: (des="构建供应商报价单数据")
  451. * User: XMing
  452. * Date: 2020/12/16
  453. * Time: 6:01 下午
  454. * @param array $params
  455. * @param int $supplierId
  456. * @return array
  457. */
  458. public static function buildSupplierOfferPriceSheetDetailsData(array $params, int $supplierId): array
  459. {
  460. return [
  461. 'supplierId' => getArrayItem($params, 'supplierId', $supplierId),
  462. // int(10) DEFAULT '0' COMMENT '供应商id',
  463. 'linkId' => getArrayItem($params, 'linkId', 0),
  464. // int(10) DEFAULT '0' COMMENT '单据id',
  465. 'materielId' => getArrayItem($params,'materielId',0),
  466. // int(10) NOT NULL COMMENT '物料id',
  467. 'offerPrice' => json_encode(getArrayItem($params, 'offerPrice', null)),
  468. // json NOT NULL COMMENT '价格数据',
  469. 'createTime' => getArrayItem($params, 'createTime', time()),
  470. // int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
  471. 'updateTime' => getArrayItem($params, 'updateTime', time()),
  472. // int(10) NOT NULL DEFAULT '0' COMMENT '更新时间',
  473. ];
  474. }
  475. /**
  476. * Doc: (des="报价单审核")
  477. * User: XMing
  478. * Date: 2020/12/21
  479. * Time: 4:23 下午
  480. * @param int $id
  481. * @return ResultWrapper
  482. */
  483. public function audit(int $id): ResultWrapper
  484. {
  485. $dbResult = $this->objDSupplierOfferPriceSheet->update(['auditStatus' => StatusCode::$auditStatus['auditPass'],'updateTime'=>time()],$id);
  486. if ($dbResult === false){
  487. return ResultWrapper::fail($this->objDSupplierOfferPriceSheet->error(),ErrorCode::$dberror);
  488. }
  489. return ResultWrapper::success(true);
  490. }
  491. /**
  492. * Doc: (des="根据物料ids获取物料的成本价格,供应商")
  493. * User: XMing
  494. * Date: 2020/12/21
  495. * Time: 4:42 下午
  496. * @param array $selectParams
  497. * @return ResultWrapper
  498. */
  499. public function getCostPriceByMaterielIds(array $selectParams): ResultWrapper
  500. {
  501. $buildSql = self::buildDetailsSqlBySelectParams($selectParams);
  502. $lists = $this->objDSupplierOfferPriceSheetDetails->query($buildSql['sql']);
  503. if ($lists === false) {
  504. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $this->objDSupplierOfferPriceSheetDetails->error());
  505. return ResultWrapper::fail($this->objDSupplierOfferPriceSheetDetails->error(), ErrorCode::$dberror);
  506. }
  507. return ResultWrapper::success($lists);
  508. }
  509. /**
  510. * Doc: (des="sql-供应商报价单详情")
  511. * User: XMing
  512. * Date: 2020/12/21
  513. * Time: 4:44 下午
  514. * @param array $selectParams
  515. * @return array
  516. */
  517. public function buildDetailsSqlBySelectParams(array $selectParams): array
  518. {
  519. $tableName = $this->objDSupplierOfferPriceSheetDetails->get_Table();
  520. $fields = ' * ';
  521. $whereSql = '';
  522. if (isset($selectParams['supplierId']) && !empty($selectParams['supplierId'])) {
  523. $whereSql .= ' AND `supplierId` = ' . $selectParams['supplierId'];
  524. }
  525. if (isset($selectParams['materielId']) && !empty($selectParams['materielId'])){
  526. $whereSql .= ' AND `materielId` = '.$selectParams['materielId'];
  527. }
  528. if (isset($selectParams['materielIds']) && !empty($selectParams['materielId'])){
  529. $materielIdsStr = implode(',',$selectParams['materielIds']);
  530. $whereSql .= ' AND `materielId` IN ('.$materielIdsStr.') ';
  531. }
  532. if (isset($selectParams['startTime']) && !empty($selectParams['startTime'])) {
  533. $whereSql .= ' AND `createTime` BETWEEN ' . $selectParams['startTime'] . ' AND ' . $selectParams['endTime'];
  534. }
  535. $sql = 'SELECT ' . $fields . ' FROM ' . $tableName . ' WHERE `deleteStatus` = ' . StatusCode::$standard . $whereSql;
  536. return [
  537. 'sql' => $sql,
  538. 'countSql' => '',
  539. ];
  540. }
  541. }