123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- /**
- * 采购退货单商品明细数据模型
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/11/11
- * Time: 17:57
- */
- namespace JinDouYun\Model\Purchase;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Purchase\DPurchaseOutGoods;
- use Mall\Framework\Core\StatusCode;
- class MPurchaseOutGoods
- {
- private $objDPurchaseOutGoods;
- private $onlineUserId;
- private $onlineEnterpriseId;
- /**
- * MPurchaseGoods constructor.
- * @param $onlineUserId
- * @param $onlineEnterpriseId
- * @throws \Exception
- */
- public function __construct($onlineUserId, $onlineEnterpriseId)
- {
- $this->onlineUserId = $onlineUserId;
- $this->onlineEnterpriseId = $onlineEnterpriseId;
- $this->objDPurchaseOutGoods = new DPurchaseOutGoods('stock');
- $this->objDPurchaseOutGoods->setTable($this->objDPurchaseOutGoods->get_Table() . '_' . $this->onlineEnterpriseId);
- }
- /**
- * 添加采购商品信息
- * @param $params
- * @return ResultWrapper
- */
- public function addPurchaseGoods($params)
- {
- $dbResult = $this->objDPurchaseOutGoods->insert($params,true);
- if ($dbResult === false) {
- $this->objDPurchaseOutGoods->rollBack();
- return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * @param $params
- * @param $purchaseId
- * @param $deleteArray
- * @return ResultWrapper
- */
- public function editPurchaseOutGoods($params,$purchaseId, $deleteArray)
- {
- foreach ($params as $key => $val) {
- if (isset($val['id'])) {
- $id = $val['id'];
- unset($val['id']);
- $dbResult = $this->objDPurchaseOutGoods->update($val, $id);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror);
- }
- } else {
- $val['purchaseOutId'] = $purchaseId;
- $insert[] = $val;
- }
- }
- if(!empty($deleteArray)){
- $dbResult = $this->objDPurchaseOutGoods->update(['deleteStatus' => StatusCode::$delete], ['id' => $deleteArray]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror);
- }
- }
- if (!empty($insert)) {
- $dbResult = $this->objDPurchaseOutGoods->insert($insert, true);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror);
- }
- }
- return ResultWrapper::success(true);
- }
- /**
- * 通过采购退货单id获取采购单下的商品
- * @param $ids
- * @return ResultWrapper
- */
- public function getGoodsByPurchaseIds($ids)
- {
- $dbResult = $this->objDPurchaseOutGoods->select(['purchaseId'=>$ids]);
- if ($dbResult === false) {
- $this->objDPurchaseOutGoods->rollBack();
- return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success(self::formatJson($dbResult));
- }
- /**
- * @param $data
- * @return mixed
- */
- public function formatJson($data)
- {
- if (isset($data['id'])) {
- $data['unit'] = empty($data['unit']) ? '' : json_decode($data['unit'], true);
- return $data;
- }
- foreach ($data as &$v) {
- $v['unit'] = empty($v['unit']) ? '' : json_decode($v['unit'],true);
- }
- return $data;
- }
- }
|