Consult.php 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //咨询单
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  59. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  60. $role=$this->checkRole();
  61. if(!empty($role['write'])){
  62. $where[]=["b.createrid","in",$role['write']];
  63. }
  64. // if(!empty($role['platform']) ){
  65. // $where[]=["b.platform_code","in",$role['platform']];
  66. // }
  67. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  68. ->count();
  69. $total = ceil($count / $size);
  70. $page = $page >= $total ? $total : $page;
  71. $list = Db::name('consult_info')
  72. ->alias("a")
  73. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  74. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  75. ->where($where)
  76. ->page($page, $size)
  77. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  78. ->order("a.id desc")
  79. ->cursor();
  80. $data=[];
  81. foreach ($list as $value){
  82. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  83. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  84. true):[];
  85. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  86. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  87. $value['khname']="";
  88. if($value['khNo']!==""){
  89. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  90. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  91. }
  92. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  93. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  94. $data[]=$value;
  95. }
  96. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  97. }
  98. public function info(){
  99. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  100. if($id==""){
  101. return error_show(1002,"咨询单编号不能为空");
  102. }
  103. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  104. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  105. $fo['can']=$in;
  106. if(empty($fo)){
  107. return error_show(1002,"未找到咨询单编号");
  108. }else{
  109. return app_show(0,"获取成功",$fo);
  110. }
  111. }
  112. public function del(){
  113. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  114. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  115. if($de==false){
  116. return error_show(1002,'咨询单信息未找到');
  117. }
  118. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  119. if($dell){
  120. return error_show(0,"删除成功");
  121. }else
  122. return error_show(1002,"删除失败");
  123. }
  124. public function create(){
  125. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  126. if($is_project===""){
  127. return error_show(1002,"参数is_project不能为空");
  128. }
  129. if($is_project==1){
  130. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  131. if($projectNo===""){
  132. return error_show(1002,"参数projectNo不能为空");
  133. }
  134. }
  135. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  136. if($khNo===""){
  137. return error_show(1002,"参数khNo不能为空");
  138. }
  139. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  140. if($companyNo===""){
  141. return error_show(1002,"参数companyNo不能为空");
  142. }
  143. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  144. if($endtime===""){
  145. return error_show(1002,"参数endtime不能为空");
  146. }
  147. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  148. "";
  149. if($platform_code===""){
  150. return error_show(1002,"参数platform_code不能为空");
  151. }
  152. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  153. if($ladder==""){
  154. return error_show(1005,"参数ladder不能为空");
  155. }
  156. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  157. if($token==''){
  158. return error_show(105,"参数token不能为空");
  159. }
  160. $user =GetUserInfo($token);
  161. if(empty($user)||$user['code']!=0){
  162. return error_show(102,"用户数据不存在");
  163. }
  164. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  165. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  166. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  167. $zxNo=makeNo("ZX");
  168. Db::startTrans();
  169. try{
  170. $data=[
  171. "zxNo"=>$zxNo,
  172. "createrid"=>$createrid,
  173. "creater"=>$creater,
  174. "is_project"=>$is_project,
  175. "projectNo"=>isset($projectNo) ? $projectNo:"",
  176. "khNo"=>$khNo,
  177. "companyNo"=>$companyNo,
  178. "endtime"=>$endtime,
  179. "salesman"=>$creater,
  180. "platform_code"=>$platform_code,
  181. "saleid"=>$createrid,
  182. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  183. "status"=>0,
  184. "is_del"=>0,
  185. "addtime"=>date("Y-m-d H:i:s"),
  186. "updatetime"=>date("Y-m-d H:i:s"),
  187. ];
  188. $zx = Db::name("consult_order")->insert($data);
  189. if($zx){
  190. //判断是否是项目,且该项目是否存在台账记录中
  191. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  192. foreach ($ladder as $value){
  193. $infoNo=makeNo("IF");
  194. $specinfo=[];
  195. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  196. foreach ($value["specinfo"] as $v){
  197. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  198. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  199. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  200. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  201. $specinfo[]=$v;
  202. }
  203. }
  204. $info=[
  205. "infoNo"=>$infoNo,
  206. "zxNo"=>$zxNo,
  207. "spuCode"=>"",
  208. "good_name"=>$value['good_name'],
  209. "good_img"=>$value['good_img'],
  210. "cat_id"=>$value['cat_id'],
  211. "unit"=>$value['unit'],
  212. "brand_id"=>$value['brand_id'],
  213. "arrival_time"=>$value['arrival_time'],
  214. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  215. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  216. "is_addrs"=>$value['is_addrs'],
  217. "is_custom"=>$value['is_custom'],
  218. "metal_id"=>$value['metal_id'],
  219. "config"=>isset($value['config'])?$value['config']:"",
  220. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  221. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  222. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  223. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  224. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  225. "budget_price"=>$value['budget_price'],
  226. "num"=>$value['num'],
  227. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  228. "use_desc"=>$value['use_desc'],
  229. "remark"=>$value['remark'],
  230. "status"=>1,
  231. "is_del"=>0,
  232. "addtime"=>date("Y-m-d H:i:s"),
  233. "updatetime"=>date("Y-m-d H:i:s"),
  234. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  235. ];
  236. $up = Db::name("consult_info")->insert($info);
  237. if(!$up){
  238. Db::rollback();
  239. return error_show(1004,'添加失败');
  240. }else{
  241. //修改状态,添加待办
  242. ActionLog::logAdd($this->post['token'], [
  243. "order_code" => $infoNo,//咨询单详情编号
  244. "status" => 1,//这里的status是之前的值
  245. "action_remark" => '',//备注
  246. "action_type" => "create"//新建create,编辑edit,更改状态status
  247. ], "ZXD", 1, $info);
  248. // ProcessOrder::AddProcess($this->post['token'], [
  249. // "order_type" => 'ZXD',
  250. // "order_code" => $infoNo,//咨询单详情编号
  251. // "order_id" => 0,
  252. // "order_status" => 1
  253. // ]);
  254. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  255. if (isset($stand_exists)) {
  256. Db::name('standing_book')
  257. ->where('id', $stand_exists['id'])
  258. ->update([
  259. 'infoNo' => $infoNo,
  260. 'updatetime' => date('Y-m-d H:i:s')
  261. ]);
  262. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  263. } else {
  264. //添加台账信息
  265. Db::name('standing_book')
  266. ->insert([
  267. 'standBookNo' => makeNo("IO"),
  268. 'projectNo' => isset($projectNo) ? $projectNo : '',
  269. 'infoNo' => $infoNo,
  270. 'addtime' => date('Y-m-d H:i:s'),
  271. 'updatetime' => date('Y-m-d H:i:s')
  272. ]);
  273. }
  274. }
  275. }
  276. Db::commit();
  277. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  278. }else{
  279. Db::rollback();
  280. return error_show(1004,"新建失败");
  281. }
  282. }catch (\Exception $e){
  283. Db::rollback();
  284. return error_show(1003,$e->getMessage());
  285. }
  286. }
  287. public function zxinfo(){
  288. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  289. if($infoNo==""){
  290. return error_show(1004,"参数infoNo不能为空");
  291. }
  292. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  293. if($zxinfo==false){
  294. return error_show(1004,"未找到信息数据");
  295. }
  296. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  297. if($zxorder==false){
  298. return error_show(1004,"未找到咨询信息数据");
  299. }
  300. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  301. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  302. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  303. $zxinfo['khname']="";
  304. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  305. $zxinfo['khNo']="";
  306. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  307. $zxinfo['brand']="";
  308. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  309. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  310. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  311. $zxinfo['company']="";
  312. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  313. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  314. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  315. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  316. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  317. $zxinfo['project_name']="";
  318. $zxinfo['budget_total']="";
  319. $zxinfo['departinfo']=[];
  320. $zxinfo['unit_name']="";
  321. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  322. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  323. if($zxorder['khNo']!==""){
  324. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  325. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  326. $zxinfo['khNo']= $zxorder['khNo'];
  327. }
  328. if($zxinfo['unit']!==""){
  329. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  330. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  331. }
  332. if($zxinfo['brand_id']!==""){
  333. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  334. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  335. }
  336. if($zxorder['companyNo']!==""){
  337. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  338. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  339. }
  340. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  341. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  342. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  343. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  344. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  345. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  346. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  347. }
  348. if($zxorder['depart']>0){
  349. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  350. }
  351. if($zxorder['platform_code']>0){
  352. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  353. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  354. }
  355. return app_show(0,"获取成功",$zxinfo);
  356. }
  357. public function zxedit(){
  358. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  359. if($infoNo==""){
  360. return error_show(1004,"参数infoNo不能为空");
  361. }
  362. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  363. if($zxinfo==false){
  364. return error_show(1004,"未找到信息数据");
  365. }
  366. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  367. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  368. if($good_name==""){
  369. return error_show(1003,"参数good_name不能为空");
  370. }
  371. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  372. if($good_img==""){
  373. return error_show(1003,"参数good_img不能为空");
  374. }
  375. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  376. if($cat_id==""){
  377. return error_show(1003,"参数cat_id不能为空");
  378. }
  379. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  380. if($unit==""){
  381. return error_show(1003,"参数unit不能为空");
  382. }
  383. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  384. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  385. if($arrival_time==""){
  386. return error_show(1003,"参数arrival_time不能为空");
  387. }
  388. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  389. if($specin==""){
  390. return error_show(1003,"参数specinfo不能为空");
  391. }
  392. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  393. // if($cost_desc==""){
  394. // return error_show(1003,"参数cost_desc不能为空");
  395. // }
  396. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  397. if($is_addrs===""){
  398. return error_show(1003,"参数is_addrs不能为空");
  399. }
  400. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  401. if($is_custom===""){
  402. return error_show(1003,"参数is_custom不能为空");
  403. }
  404. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  405. if($metal_id===""){
  406. return error_show(1003,"参数metal_id不能为空");
  407. }
  408. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  409. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  410. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  411. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  412. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  413. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  414. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  415. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  416. if($num===""){
  417. return error_show(1003,"参数num不能为空");
  418. }
  419. if($budget_price===""){
  420. return error_show(1003,"参数budget_price不能为空");
  421. }
  422. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  423. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  424. if($use_desc==""){
  425. return error_show(1003,"参数use_desc不能为空");
  426. }
  427. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  428. if($remark==""){
  429. return error_show(1003,"参数remark不能为空");
  430. }
  431. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  432. if($endtime==""){
  433. return error_show(1003,"参数endtime不能为空");
  434. }
  435. if($metal_id!=0){
  436. if($config==""){
  437. return error_show(1003,"参数config不能为空");
  438. }
  439. if($other_config==""){
  440. return error_show(1003,"参数other_config不能为空");
  441. }
  442. if($specs_weight===""){
  443. return error_show(1003,"参数specs_weight不能为空");
  444. }
  445. if($gold_price===""){
  446. return error_show(1003,"参数gold_price不能为空");
  447. }
  448. }
  449. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  450. if($token==''){
  451. return error_show(102,"参数token不能为空");
  452. }
  453. $user =GetUserInfo($token);
  454. if(empty($user)||$user['code']!=0){
  455. return error_show(105,"用户数据不存在");
  456. }
  457. $specinfo=[];
  458. foreach ($specin as $v){
  459. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  460. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  461. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  462. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  463. $specinfo[]=$v;
  464. }
  465. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  466. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  467. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  468. Db::startTrans();
  469. try{
  470. $innew =makeNo("IF");
  471. $info=[
  472. "infoNo"=>$innew,
  473. "zxNo"=>$zxinfo['zxNo'],
  474. "spuCode"=>"",
  475. "good_name"=>$good_name,
  476. "good_img"=>$good_img,
  477. "cat_id"=>$cat_id,
  478. "unit"=>$unit,
  479. "brand_id"=>$brand_id,
  480. "arrival_time"=>$arrival_time,
  481. "specinfo"=>json_encode($specinfo),
  482. // "color"=>$color,
  483. // "material"=>$material,
  484. "cost_desc"=>$cost_desc,
  485. "is_addrs"=>$is_addrs,
  486. "is_custom"=>$is_custom,
  487. "metal_id"=>$metal_id,
  488. "config"=>$config,
  489. "other_config"=>$other_config,
  490. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  491. "gold_price"=>$gold_price===""? 0 : $gold_price,
  492. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  493. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  494. "budget_price"=>$budget_price,
  495. "num"=>$num,
  496. "pgNo"=>$pgNo,
  497. "use_desc"=>$use_desc,
  498. "remark"=>$remark,
  499. "status"=>1,
  500. "is_del"=>0,
  501. "addtime"=>date("Y-m-d H:i:s"),
  502. "updatetime"=>date("Y-m-d H:i:s"),
  503. 'bargain_status'=>1,
  504. 'enclosure_file'=>$enclosure_file
  505. ];
  506. $up = Db::name("consult_info")->insert($info);
  507. if($up){
  508. //操作记录
  509. ActionLog::logAdd($this->post['token'], [
  510. "order_code" => $innew,//咨询单详情编号
  511. "status" => 1,//这里的status是之前的值
  512. "action_remark" => '',//备注
  513. "action_type" => "edit"//新建create,编辑edit,更改状态status
  514. ], "ZXD", 1, $this->post);
  515. // ProcessOrder::AddProcess($this->post['token'], [
  516. // "order_type" => 'ZXD',
  517. // "order_code" => $innew,//咨询单详情编号
  518. // "order_id" => 0,
  519. // "order_status" => 1
  520. // ]);
  521. if (!empty($bidlist)){
  522. foreach ($bidlist as $value){
  523. unset($value['id']);
  524. $value['infoNo']=$innew;
  525. $value['bidNo']=makeNo("BD");
  526. $value['spuCode']=makeNo("SKU");
  527. $value['status'] =0;
  528. $value['updatetime'] =date("Y-m-d H:i:s");
  529. $in = Db::name("consult_bids")->insert($value);
  530. if($in==false){
  531. Db::rollback();
  532. return error_show(1004,"反馈商品新建失败");
  533. }
  534. ActionLog::logAdd($this->post['token'], [
  535. "order_code" => $innew,//咨询单详情编号
  536. "status" => 1,//这里的status是之前的值
  537. "action_remark" => '',//备注
  538. "action_type" => "edit"//新建create,编辑edit,更改状态status
  539. ], "FKD", 1, $this->post);
  540. }
  541. }
  542. $zxinfo["bargain_status"] =1;
  543. $zxinfo["bargain_code"] =$innew;
  544. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  545. $bar=Db::name("consult_info")->save($zxinfo);
  546. if($bar==false){
  547. Db::rollback();
  548. return error_show(1004,"反馈商品更新失败");
  549. }else{
  550. //修改状态,添加待办
  551. ActionLog::logAdd($this->post['token'], [
  552. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  553. "status" => $zxinfo['status'],//这里的status是之前的值
  554. "action_remark" => '',//备注
  555. "action_type" => "edit"//新建create,编辑edit,更改状态status
  556. ], "ZXD", $zxinfo['status'], $zxinfo);
  557. }
  558. //更新consule_order记录
  559. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  560. 'updatetime'=>date('Y-m-d H:i:s')]);
  561. if($op==false){
  562. Db::rollback();
  563. return error_show(1004,'咨询单结束时间更新失败');
  564. }
  565. Db::commit();
  566. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  567. }
  568. }catch (\Exception $e){
  569. Db::rollback();
  570. return error_show(1004,$e->getMessage());
  571. }
  572. }
  573. //** 发布竞标任务 */
  574. public function bargain(){
  575. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  576. if($infoNo==""){
  577. return error_show(1004,"参数infoNo不能为空");
  578. }
  579. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  580. if($zxinfo==false){
  581. return error_show(1004,"未找到信息数据");
  582. }
  583. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  584. if($status===""){
  585. return error_show(1004,"参数status不能为空");
  586. }
  587. // if($status==1&&$zxinfo['status']>1){
  588. // $zxinfo['bargain_num']=+1;
  589. // }
  590. $old_zxinfo_status = $zxinfo['status'];
  591. $zxinfo['status']=$status;
  592. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  593. $up = Db::name("consult_info")->save($zxinfo);
  594. if($up){
  595. //修改状态,添加待办
  596. ActionLog::logAdd($this->post['token'], [
  597. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  598. "status" => $old_zxinfo_status,//这里的status是之前的值
  599. "action_remark" => '',//备注
  600. "action_type" => "status"//新建create,编辑edit,更改状态status
  601. ], "ZXD", $zxinfo['status'], $zxinfo);
  602. return app_show(0,"状态更新成功");
  603. }else{
  604. return error_show(1003,"状态更新失败");
  605. }
  606. }
  607. //反馈商品添加
  608. public function feadback(){
  609. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  610. if($infoNo==""){
  611. return error_show(1002,"参数infoNo不能为空");
  612. }
  613. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  614. if($zxinfo==false){
  615. return error_show(1003,"未找到信息数据");
  616. }
  617. if($zxinfo['status']!=1){
  618. return error_show(1004,"任务未进行");
  619. }
  620. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  621. if($zx==false){
  622. return error_show(1003,"未找咨询信息数据");
  623. }
  624. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  625. if($pname==""){
  626. return error_show(1002,"参数pname不能为空");
  627. }
  628. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  629. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  630. if($cat_id==""){
  631. return error_show(1002,"参数cat_id不能为空");
  632. }
  633. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  634. if($specin==""){
  635. return error_show(1003,"参数specinfo不能为空");
  636. }
  637. $specinfo=[];
  638. foreach ($specin as $v){
  639. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  640. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  641. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  642. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  643. $specinfo[]=$v;
  644. }
  645. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  646. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  647. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  648. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  649. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  650. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  651. :"";
  652. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  653. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  654. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  655. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  656. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  657. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  658. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  659. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  660. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  661. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  662. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  663. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  664. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  665. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  666. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  667. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  668. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  669. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  670. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  671. if($nake_fee==="" ){
  672. return error_show(1004,"参数nake_fee不能为空");
  673. }
  674. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  675. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  676. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  677. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  678. if($delivery_place==''){
  679. return error_show(1002,"参数delivery_place不能为空");
  680. }
  681. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  682. if($token==''){
  683. return error_show(1002,"参数token不能为空");
  684. }
  685. $user =GetUserInfo($token);
  686. if(empty($user)||$user['code']!=0){
  687. return error_show(1005,"用户数据不存在");
  688. }
  689. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  690. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  691. $bidNo=makeNo("BD");
  692. $spucode=makeNo("SKU");
  693. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  694. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  695. //部分参数的大小校验
  696. $vali = Validate::rule([
  697. 'expire_day|有效时长'=>'require|elt:214748364',
  698. 'delivery_day|物流时长'=>'require|elt:214748364',
  699. 'work_day|生产工期'=>'require|elt:214748364',
  700. 'weight|总重量'=>'require|max:10',
  701. ]);
  702. $temp = [
  703. 'expire_day'=>$expire_day,
  704. 'delivery_day'=>$delivery_day,
  705. 'work_day'=>$work_day,
  706. 'weight'=>$weight,
  707. ];
  708. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  709. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  710. $cat_top_list = made($cat_id);
  711. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  712. if ($is_gold_price == 1 && $cat_top_id == 6) {
  713. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  714. ->find();
  715. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  716. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  717. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  718. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  719. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  720. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  721. $saleprice = $total_fee/ (1 - $budget);
  722. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  723. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  724. }else{
  725. if($nake_fee){
  726. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  727. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  728. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  729. }else{
  730. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  731. (1 - $budget);
  732. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  733. }
  734. }
  735. $data=[
  736. "bidNo"=>$bidNo,
  737. "infoNo"=>$infoNo,
  738. "zxNo"=>$zxinfo['zxNo'],
  739. "spuCode"=>$spucode,
  740. "good_name"=>$pname,
  741. "brand_id"=>$brandid,
  742. "cat_id"=>$cat_id,
  743. "specinfo"=>json_encode($specinfo),
  744. "unit_id"=>$unit_id,
  745. "cost_desc"=>$cost_desc,
  746. "work_day"=>$work_day,
  747. "delivery_day"=>$delivery_day,
  748. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  749. "expire_day"=>$expire_day,
  750. "origin_place"=>$origin_place,
  751. "supplierNo"=>$supplierNo,
  752. "pay_way"=>$pay_way,
  753. "tax"=>$tax,
  754. "send_way"=>$send_way,
  755. "metal_id"=>$metal_id,
  756. "is_gold_price"=>$is_gold_price,
  757. "config"=>$config,
  758. "other_config"=>$other_config,
  759. "weight"=>$weight,
  760. "good_weight"=>$good_weight,
  761. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  762. "is_diff"=>$is_diff,
  763. "demo_fee"=>$demo_fee,
  764. "delivery_fee"=>$delivery_fee,
  765. "open_fee"=>$open_fee,
  766. "pakge_fee"=>$pakge_fee,
  767. "nake_fee"=>$nake_fee,
  768. "mark_fee"=>$mark_fee,
  769. "cert_fee"=>$cert_fee,
  770. "cost_fee"=>$cost_fee,
  771. "total_fee"=>$total_fee,
  772. "supply_area"=>$supply_area,
  773. "remark"=>$remark,
  774. "sale_price"=>$saleprice,
  775. "sale_cost_fee"=>$sale_cost_fee,
  776. "origin_cost_fee"=>$sale_cost_fee,
  777. "origin_price"=>$saleprice,
  778. "createrid"=>$createrid,
  779. "creater"=>$creater,
  780. "status"=>$zxinfo['status']==1 ?1 :2,
  781. "is_del"=>0,
  782. "addtime"=>date("Y-m-d H:i:s"),
  783. "updatetime"=>date("Y-m-d H:i:s"),
  784. 'delivery_place'=>$delivery_place//发货地
  785. ];
  786. Db::startTrans();
  787. try{
  788. $insert= Db::name("consult_bids")->insert($data);
  789. if($insert){
  790. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  791. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  792. if($projectinfo==false){
  793. Db::rollback();
  794. return error_show(1006,"未找到项目信息");
  795. }
  796. $temp=[];
  797. $temp['spuCode']=$spucode;
  798. $temp['skuCode']="";
  799. $temp['pgNo']=$zxinfo['pgNo'];
  800. $temp['projectNo']=$zx['projectNo'];
  801. $temp['good_name']=$pname;
  802. $temp['good_type']=$projectinfo['good_type'];
  803. $temp['data_source']=2;
  804. $temp['cat_id']=$cat_id;
  805. $temp['budget_price']=$projectinfo['budget_price'];
  806. $temp['sale_price']=$saleprice;
  807. $temp['origin_price']=$total_fee;
  808. $temp['num']=$zxinfo['num'];
  809. $temp['status']=0;
  810. $temp['is_del']=0;
  811. $temp['creater']=$creater;
  812. $temp['createrid']=$createrid;
  813. $temp['addtime']=date("Y-m-d H:i:s");
  814. $temp['updatetime']=date("Y-m-d H:i:s");
  815. $nu = Db::name("project_feedback")->insert($temp);
  816. if($nu==false){
  817. Db::rollback();
  818. return error_show(1006,"项目反馈失败");
  819. }else{
  820. $old_projectinfo_status = $projectinfo['status'];
  821. $projectinfo['status']=2;
  822. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  823. $up = Db::name("project_info")->save($projectinfo);
  824. if($up){
  825. //修改状态,添加待办,只记录动作
  826. ActionLog::logAdd($this->post['token'], [
  827. "order_code" => $projectinfo['pgNo'],//编码
  828. "status" => $old_projectinfo_status,//这里的status是之前的值
  829. "action_remark" => '',//备注
  830. "action_type" => "status"//新建create,编辑edit,更改状态status
  831. ], "PRI", 2, $projectinfo);
  832. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  833. ->count();
  834. if($count==0){
  835. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  836. if($projetc!=false){
  837. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  838. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  839. if($proc==false){
  840. Db::rollback();
  841. return error_show(1006,"项目反馈失败");
  842. }else{
  843. //修改状态,添加待办
  844. ActionLog::logAdd($this->post['token'], [
  845. "order_code" => $projetc['projectNo'],//项目编码
  846. "status" => 1,//这里的status是之前的值
  847. "action_remark" => '',//备注
  848. "action_type" => "status"//新建create,编辑edit,更改状态status
  849. ], "PRO", 2, $projetc);
  850. ProcessOrder::AddProcess($this->post['token'], [
  851. "order_type" => 'PRO',
  852. "order_code" => $projetc['projectNo'],
  853. "order_id" => $projetc['id'],
  854. "order_status" => 2,"before_status"=>1
  855. ]);
  856. }
  857. }
  858. }
  859. }
  860. }
  861. }
  862. Db::commit();
  863. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  864. }else{
  865. Db::rollback();
  866. return error_show(1006,"反馈失败");
  867. }
  868. }catch (\Exception $e){
  869. Db::rollback();
  870. return error_show(1006,$e->getMessage());
  871. }
  872. }
  873. //反馈商品详情
  874. public function feadinfo(){
  875. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  876. if($bidNo==""){
  877. return error_show(1004,"参数bidNo不能为空");
  878. }
  879. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  880. if($info==false){
  881. return error_show(1004,"未找到商品数据");
  882. }
  883. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  884. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  885. $info['cat_info'] = made($info['cat_id'],[]);
  886. $info['noble_weight'] = $info['good_weight'];
  887. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  888. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  889. if($info['brand_id']!=0){
  890. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  891. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  892. }else{
  893. $info["brand_name"]="";
  894. $info["brand_id"]="";
  895. }
  896. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  897. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  898. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  899. $god=[
  900. "metal_id"=>$info['metal_id'],
  901. "weight"=>$info["good_weight"],
  902. "demo_fee"=>$info["demo_fee"],
  903. "delivery_fee"=>$info["delivery_fee"],
  904. "open_fee"=>$info["open_fee"],
  905. "packing_fee"=>$info["pakge_fee"],
  906. "mark_fee"=>$info["mark_fee"],
  907. "nake_fee"=>$info["nake_fee"],
  908. "cert_fee"=>$info["cert_fee"],
  909. "cost_fee"=>$info["cost_fee"],
  910. "num"=>$bidinfo["num"],
  911. ];
  912. if($info['is_gold_price']==1){
  913. $price = GoldPrice($god, $budget/100);
  914. $info['sale_price'] =round($price,2);
  915. }
  916. $info['specinfo'] = json_decode($info['specinfo'],true);
  917. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  918. if($info['delivery_place']!=""){
  919. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  920. }
  921. $info['delivery_place_cn']=GetAddr(json_encode($place));
  922. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  923. if($info['origin_place']!=""){
  924. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  925. }
  926. $info['origin_place_cn']=GetAddr(json_encode($place));
  927. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  928. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  929. $info['bargain'] =$bargain;
  930. $info['good_img'] = explode(',',$info['good_img']);
  931. return app_show(0,"获取成功",$info);
  932. }
  933. //反馈商品编辑
  934. public function feededit(){
  935. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  936. if($bidNo==""){
  937. return error_show(1002,"参数bidNo不能为空");
  938. }
  939. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  940. if($bidinfo==false){
  941. return error_show(1003,"未找到信息数据");
  942. }
  943. if($bidinfo['status']>=5){
  944. return error_show(1004,"咨询单已确认无法修改");
  945. }
  946. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  947. if($zxinfo==false){
  948. return error_show(1003,"未找到信息数据");
  949. }
  950. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  951. if($zx==false){
  952. return error_show(1003,"未找咨询信息数据");
  953. }
  954. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  955. if($pname==""){
  956. return error_show(1002,"参数pname不能为空");
  957. }
  958. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  959. // if($brandid==""){
  960. // return error_show(1002,"参数brandid不能为空");
  961. // }
  962. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  963. if($cat_id==""){
  964. return error_show(1002,"参数cat_id不能为空");
  965. }
  966. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  967. if($specin==""){
  968. return error_show(1003,"参数specinfo不能为空");
  969. }
  970. $specinfo=[];
  971. foreach ($specin as $v){
  972. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  973. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  974. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  975. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  976. $specinfo[]=$v;
  977. }
  978. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  979. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  980. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  981. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  982. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  983. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  984. :"";
  985. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  986. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  987. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  988. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  989. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  990. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  991. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  992. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  993. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  994. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  995. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  996. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  997. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  998. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  999. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1000. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1001. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1002. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1003. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1004. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1005. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1006. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1007. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1008. if($delivery_place==''){
  1009. return error_show(1002,"参数delivery_place不能为空");
  1010. }
  1011. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1012. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1013. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1014. $cat_top_list = made($cat_id);
  1015. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1016. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1017. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1018. ->find();
  1019. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1020. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1021. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1022. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1023. $saleprice = $total_fee / (1 - $budget);
  1024. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1025. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1026. }else{
  1027. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1028. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1029. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1030. }
  1031. Db::startTrans();
  1032. try{
  1033. $data=[
  1034. "good_name"=>$pname,
  1035. "brand_id"=>$brandid,
  1036. "cat_id"=>$cat_id,
  1037. "specinfo"=>json_encode($specinfo),
  1038. // "material"=>$material,
  1039. "unit_id"=>$unit_id,
  1040. "cost_desc"=>$cost_desc,
  1041. "work_day"=>$work_day,
  1042. "delivery_day"=>$delivery_day,
  1043. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1044. "expire_day"=>$expire_day,
  1045. "origin_place"=>$origin_place,
  1046. "supplierNo"=>$supplierNo,
  1047. "pay_way"=>$pay_way,
  1048. "tax"=>$tax,
  1049. "send_way"=>$send_way,
  1050. "metal_id"=>$metal_id,
  1051. "is_gold_price"=>$is_gold_price,
  1052. "config"=>$config,
  1053. "other_config"=>$other_config,
  1054. "weight"=>$weight,
  1055. "good_weight"=>$noble_weight,
  1056. "is_diff"=>$is_diff,
  1057. "demo_fee"=>$demo_fee,
  1058. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1059. "delivery_fee"=>$delivery_fee,
  1060. "open_fee"=>$open_fee,
  1061. "pakge_fee"=>$pakge_fee,
  1062. "nake_fee"=>$nake_fee,
  1063. "mark_fee"=>$mark_fee,
  1064. "cert_fee"=>$cert_fee,
  1065. "cost_fee"=>$cost_fee,
  1066. "sale_cost_fee"=>$sale_cost_fee,
  1067. "origin_cost_fee"=>$sale_cost_fee,
  1068. "total_fee"=>$total_fee,
  1069. "sale_price"=>$saleprice,
  1070. "origin_price"=>$saleprice,
  1071. "supply_area"=>$supply_area,
  1072. "remark"=>$remark,
  1073. "status"=>0,
  1074. "updatetime"=>date("Y-m-d H:i:s"),
  1075. 'delivery_place' => $delivery_place
  1076. ];
  1077. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1078. if($insert){
  1079. if($zxinfo['bargain_status']==1){
  1080. $zxinfo['bargain_status']=0;
  1081. $infoip =Db::name("consult_info")->save($zxinfo);
  1082. if($infoip==false){
  1083. Db::rollback();
  1084. return error_show(1006,"咨询信息状态更新失败");
  1085. }
  1086. }
  1087. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1088. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1089. if($projectinfo==false){
  1090. Db::rollback();
  1091. return error_show(1006,"未找到项目信息");
  1092. }
  1093. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1094. if($feed==false){
  1095. Db::rollback();
  1096. return error_show(1006,"未找到项目反馈信息");
  1097. }
  1098. $feed['good_name']=$pname;
  1099. $feed['good_type']=$projectinfo['good_type'];
  1100. $feed['cat_id']=$cat_id;
  1101. $feed['sale_price']=$saleprice;
  1102. $feed['origin_price']=$total_fee;
  1103. $feed['updatetime']=date("Y-m-d H:i:s");
  1104. $temp['updatetime']=date("Y-m-d H:i:s");
  1105. $nu = Db::name("project_feedback")->save($feed);
  1106. if($nu==false){
  1107. Db::rollback();
  1108. return error_show(1006,"项目反馈失败");
  1109. }else{
  1110. $old_projectinfo_status = $projectinfo['status'];
  1111. $projectinfo['status']=2;
  1112. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1113. $up = Db::name("project_info")->save($projectinfo);
  1114. if($up){
  1115. //修改状态,添加待办,只记录动作
  1116. ActionLog::logAdd($this->post['token'], [
  1117. "order_code" => $projectinfo['pgNo'],//编码
  1118. "status" => $old_projectinfo_status,//这里的status是之前的值
  1119. "action_remark" => '',//备注
  1120. "action_type" => "status"//新建create,编辑edit,更改状态status
  1121. ], "PRI", 2, $projectinfo);
  1122. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->count();
  1123. if ($count == 0) {
  1124. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1125. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
  1126. if ($project_id) {
  1127. $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1128. if ($proc == false) {
  1129. Db::rollback();
  1130. return error_show(1006, "项目反馈失败");
  1131. }else{
  1132. //修改状态,添加待办
  1133. ActionLog::logAdd($this->post['token'], [
  1134. "order_code" => $projectinfo['projectNo'],//项目编码
  1135. "status" => 1,//这里的status是之前的值
  1136. "action_remark" => '',//备注
  1137. "action_type" => "status"//新建create,编辑edit,更改状态status
  1138. ], "PRO", 2, $this->post);
  1139. ProcessOrder::AddProcess($this->post['token'], [
  1140. "order_type" => 'PRO',
  1141. "order_code" => $projectinfo['projectNo'],
  1142. "order_id" => $project_id,
  1143. "order_status" => 2,"before_status"=>1
  1144. ]);
  1145. }
  1146. }
  1147. }
  1148. }
  1149. }
  1150. }
  1151. Db::commit();
  1152. return app_show(0,"编辑成功");
  1153. }else{
  1154. Db::rollback();
  1155. return error_show(1004,"编辑失败");
  1156. }
  1157. }catch (\Exception $e){
  1158. Db::rollback();
  1159. return error_show(1004,$e->getMessage());
  1160. }
  1161. }
  1162. public function bargain_add(){
  1163. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1164. if($bidNo===""){
  1165. return error_show(1004,"参数bidNo不能为空");
  1166. }
  1167. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1168. if($info==false){
  1169. return error_show(1004,"未找到商品数据");
  1170. }
  1171. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1172. if($consult==false){
  1173. return error_show(1004,"未找到咨询数据");
  1174. }
  1175. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1176. if($bargain_price===""){
  1177. return error_show(1004,"参数bargain_price不能为空");
  1178. }
  1179. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1180. if($info['is_gold_price']==1){
  1181. if($cost_price==""){
  1182. return error_show(1004,"参数cost_price不能为空");
  1183. }
  1184. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1185. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1186. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1187. ->find();
  1188. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1189. }
  1190. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1191. // if($bargain_reason===""){
  1192. // return error_show(1004,"参数bargain_reason不能为空");
  1193. // }
  1194. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1195. if($infos==false){
  1196. return error_show(1004,"未找到商品数据");
  1197. }
  1198. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1199. return error_show(1004,"咨询单招标未结束或已确认商品");
  1200. }
  1201. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1202. if($token==''){
  1203. return error_show(105,"参数token不能为空");
  1204. }
  1205. $user =GetUserInfo($token);
  1206. if(empty($user)||$user['code']!=0){
  1207. return error_show(1002,"用户数据不存在");
  1208. }
  1209. //新增两个字段
  1210. //议价备注
  1211. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1212. //议价原因id
  1213. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1214. if ($result_info_id != '') {
  1215. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1216. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1217. }
  1218. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1219. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1220. $bargainNo =makeNo("BA");
  1221. Db::startTrans();//::todo 金价 毛利计算
  1222. try{
  1223. $data=[
  1224. "bidsNo"=>$bidNo,
  1225. "infoNo"=>$info['infoNo'],
  1226. "zxNo"=>$info['zxNo'],
  1227. "bargainNo"=>$bargainNo,
  1228. "bargain_type"=>1,
  1229. "bargain_reason"=>$bargain_reason,
  1230. "sale_price"=>$info['sale_price'],
  1231. "cost_before_price"=>$info['sale_cost_fee'],
  1232. "cost_after_price"=>$cost_price,
  1233. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1234. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1235. "after_price"=>$bargain_price,
  1236. "exam_info"=>"",
  1237. "status"=>0,
  1238. "is_del"=>0,
  1239. "creater"=>$creater,
  1240. "createrid"=>$createrid,
  1241. "addtime"=>date("Y-m-d H:i:s"),
  1242. "updatetime"=>date("Y-m-d H:i:s"),
  1243. 'bargain_remark'=>$bargain_remark,
  1244. 'result_info_id'=>$result_info_id,
  1245. ];
  1246. $int = Db::name("bargain_order")->insert($data);
  1247. if($int){
  1248. //修改状态,添加待办
  1249. ActionLog::logAdd($this->post['token'], [
  1250. "order_code" => $bargainNo,//咨询单详情编号
  1251. "status" => 0,//这里的status是之前的值
  1252. "action_remark" => '',//备注
  1253. "action_type" => "status"//新建create,编辑edit,更改状态status
  1254. ], "YJD", $data['status'], $data);
  1255. ProcessOrder::AddProcess($this->post['token'], [
  1256. "order_type" => 'YJD',
  1257. "order_code" => $bargainNo,
  1258. "order_id" =>Db::name("bargain_order")->getLastInsID(),
  1259. "order_status" =>0,"before_status"=>0
  1260. ]);
  1261. $odlstatus=$info['status'];
  1262. $info['status']=3;
  1263. $info['updatetime']=date("Y-m-d H:i:s");
  1264. $up =Db::name("consult_bids")->save($info);
  1265. if($up){
  1266. //修改状态,添加待办
  1267. ActionLog::logAdd($this->post['token'], [
  1268. "order_code" => $bidNo,//咨询单详情编号
  1269. "status" => $odlstatus,//这里的status是之前的值
  1270. "action_remark" => '',//备注
  1271. "action_type" => "status"//新建create,编辑edit,更改状态status
  1272. ], "FKD", $info['status'], $info);
  1273. $old_infos_status = $infos['status'];
  1274. $infos['status']=3;
  1275. $infos['updatetime']=date("Y-m-d H:i:s");
  1276. $ups =Db::name("consult_info")->save($infos);
  1277. if($ups){
  1278. //修改状态,添加待办
  1279. ActionLog::logAdd($this->post['token'], [
  1280. "order_code" => $infos['infoNo'],//咨询单详情编号
  1281. "status" => $old_infos_status,//这里的status是之前的值
  1282. "action_remark" => '',//备注
  1283. "action_type" => "status"//新建create,编辑edit,更改状态status
  1284. ], "ZXD", $infos['status'], $infos);
  1285. Db::commit();
  1286. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1287. }
  1288. }
  1289. }
  1290. Db::rollback();
  1291. return error_show(1004,"议价单新建失败");
  1292. }catch (\Exception $e){
  1293. Db::rollback();
  1294. return error_show(1004,$e->getMessage());
  1295. }
  1296. }
  1297. //选择商品
  1298. public function bids_check(){
  1299. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1300. if($bidNo===""){
  1301. return error_show(1004,"参数bidNo不能为空");
  1302. }
  1303. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1304. if($info==false){
  1305. return error_show(1004,"未找到商品数据");
  1306. }
  1307. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1308. if($infos==false){
  1309. return error_show(1004,"未找到商品数据");
  1310. }
  1311. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1312. return error_show(1004,"咨询单招标未结束或已确认商品");
  1313. }
  1314. Db::startTrans();
  1315. try {
  1316. $oldstattus=$info['status'];
  1317. $info['status']=6;
  1318. $info['updatetime']=date("Y-m-d H:i:s");
  1319. $bids = Db::name("consult_bids")->save($info);
  1320. if($bids){
  1321. //修改状态,添加待办
  1322. ActionLog::logAdd($this->post['token'], [
  1323. "order_code" =>$bidNo,//咨询单详情编号
  1324. "status" => $oldstattus,//这里的status是之前的值
  1325. "action_remark" => '',//备注
  1326. "action_type" => "status"//新建create,编辑edit,更改状态status
  1327. ], "FKD", $info['status'], $info);
  1328. $old_infos_status = $infos['status'];
  1329. $infos['status']=4;
  1330. $infos['updatetime']=date("Y-m-d H:i:s");
  1331. $se = Db::name("consult_info")->save($infos);
  1332. if($se){
  1333. //修改状态,添加待办
  1334. ActionLog::logAdd($this->post['token'], [
  1335. "order_code" => $infos['infoNo'],//咨询单详情编号
  1336. "status" => $old_infos_status,//这里的status是之前的值
  1337. "action_remark" => '',//备注
  1338. "action_type" => "status"//新建create,编辑edit,更改状态status
  1339. ], "ZXD", $infos['status'], $infos);
  1340. Db::commit();
  1341. return app_show(0,"商品确定成功");
  1342. }
  1343. }
  1344. Db::rollback();
  1345. return error_show(1004,"商品确认失败");
  1346. }catch (\Exception $e){
  1347. Db::rollback();
  1348. return error_show(1004,$e->getMessage());
  1349. }
  1350. }
  1351. //议价审核
  1352. /**
  1353. * status:
  1354. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1355. */
  1356. public function bargain_status(){
  1357. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1358. if($bargainNo===""){
  1359. return error_show(1004,"参数bargainNo不能为空");
  1360. }
  1361. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1362. if($info==false){
  1363. return error_show(1004,"未找到议价数据");
  1364. }
  1365. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1366. if($bids==false){
  1367. return error_show(1004,"未找到商品数据");
  1368. }
  1369. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1370. if($coninfo==false){
  1371. return error_show(1004,"未找到咨询单数据");
  1372. }
  1373. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1374. if($status===''){
  1375. return error_show(1005,"参数status不能为空");
  1376. }
  1377. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1378. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1379. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1380. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1381. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1382. if($bids['is_gold_price']==1){
  1383. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1384. ->find();
  1385. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1386. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1387. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1388. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1389. $saleprice =$total_fe / (1 - $budget);
  1390. $rate_price = $total_fe / (1 - $rate);
  1391. $money_price =$total_fe / (1 - $money_rate);
  1392. $lower_price =$total_fe / (1 - $lower_rate);
  1393. }else{
  1394. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1395. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1396. if($bids['nake_fee']!=0){
  1397. $saleprice = ($total_fe)/ (1 - $budget);
  1398. $rate_price = ($total_fe)/ (1 - $rate);
  1399. $money_price =($total_fe)/ (1 - $money_rate);
  1400. $lower_price = ($total_fe) / (1 - $lower_rate);
  1401. }else{
  1402. $saleprice = $total_fe / (1 - $budget);
  1403. $rate_price =$total_fe/ (1 - $rate);
  1404. $money_price =$total_fe / (1 - $money_rate);
  1405. $lower_price = $total_fe/ (1 - $lower_rate);
  1406. }
  1407. }
  1408. $ra_status = $info['status'];
  1409. if($status==1){
  1410. if($info['status']==0){
  1411. if($info['after_price']<$rate_price){
  1412. $info['status']=2;
  1413. }else{
  1414. $info['status']=1;
  1415. }
  1416. }elseif($info['status']==2){
  1417. $info['status']=4;
  1418. }elseif($info['status']==4||$info['status']==5){
  1419. if($info['after_price']<$money_price){
  1420. $info['status']=7;
  1421. }else{
  1422. $info['status']=6;
  1423. }
  1424. }elseif($info['status']==7){
  1425. $info['lower_price'] =$lower_price;
  1426. if($info['after_price']<$lower_price){
  1427. $info['status']=10;
  1428. }else{
  1429. $info['status']=9;
  1430. }
  1431. }
  1432. }else{
  1433. if($info['status']==0){
  1434. $info['status']=3;
  1435. }elseif($info['status']==2){
  1436. $info['status']=4;
  1437. }elseif($info['status']==4||$info['status']==5){
  1438. $info['status']=8;
  1439. }elseif($info['status']==7){
  1440. $info['lower_price'] =$lower_price;
  1441. $info['status']=11;
  1442. }
  1443. }
  1444. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1445. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1446. if($token==''){
  1447. return error_show(105,"参数token不能为空");
  1448. }
  1449. $user =GetUserInfo($token);
  1450. if(empty($user)||$user['code']!=0){
  1451. return error_show(1002,"用户数据不存在");
  1452. }
  1453. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1454. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1455. Db::startTrans();
  1456. try{
  1457. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1458. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1459. "creater"=>$creater];
  1460. // $info['status'] =$status;
  1461. $info['remark'] =$remark;
  1462. $info['exam_info']=json_encode($examinfo) ;
  1463. $info['updatetime'] =date("Y-m-d H:i:s");
  1464. $up =Db::name("bargain_order")->save($info);
  1465. if($up){
  1466. //修改状态,添加待办
  1467. ActionLog::logAdd($this->post['token'], [
  1468. "order_code" => $bargainNo,//咨询单详情编号
  1469. "status" =>$ra_status,//这里的status是之前的值
  1470. "action_remark" => '',//备注
  1471. "action_type" => "status"//新建create,编辑edit,更改状态status
  1472. ], "YJD", $info['status'], $info);
  1473. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status];
  1474. ProcessOrder::AddProcess($token,$process);
  1475. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1476. $bidstatus=$bids['status'];
  1477. $bids['status']=5;
  1478. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1479. $bids['sale_price']=$info['after_price'];
  1480. if($bids['is_gold_price']==1){
  1481. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1482. // ->find();
  1483. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1484. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1485. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1486. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1487. }
  1488. }
  1489. $bids['updatetime']=date("Y-m-d H:i:s");
  1490. $up =Db::name("consult_bids")->save($bids);
  1491. if($up==false){
  1492. Db::rollback();
  1493. return error_show(1004,"数据更新失败");
  1494. }
  1495. ActionLog::logAdd($this->post['token'], [
  1496. "order_code" => $info["bidsNo"],//咨询单详情编号
  1497. "status" => $bidstatus,//这里的status是之前的值
  1498. "action_remark" => '',//备注
  1499. "action_type" => "status"//新建create,编辑edit,更改状态status
  1500. ], "FKD", $bids['status'], $bids);
  1501. }
  1502. Db::commit();
  1503. return app_show(0,"更新成功");
  1504. }
  1505. }catch (\Exception $e){
  1506. Db::rollback();
  1507. return error_show(1004,$e->getMessage());
  1508. }
  1509. }
  1510. public function bargain_info(){
  1511. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1512. if($bargainNo===""){
  1513. return error_show(1004,"参数bargainNo不能为空");
  1514. }
  1515. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1516. if($info==false){
  1517. return error_show(1004,"未找到议价数据");
  1518. }
  1519. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1520. if($bidinfos==false){
  1521. return error_show(1004,"未找到商品数据");
  1522. }
  1523. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1524. ->find();
  1525. if($consultinfos==false){
  1526. return error_show(1004,"未找到咨询商品数据");
  1527. }
  1528. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1529. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1530. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1531. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1532. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1533. $info['before_rate'] =round($info['before_rate']*100,2);
  1534. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1535. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1536. $info['after_rate'] = round($info['after_rate']*100,2);
  1537. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1538. if($bidinfos['brand_id']!=0){
  1539. $info['brand_id'] = $bidinfos['brand_id'];
  1540. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1541. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1542. }else{
  1543. $info["brand_name"]="";
  1544. $info["brand_id"]="";
  1545. }
  1546. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1547. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1548. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1549. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1550. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1551. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1552. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1553. $info['budget'] =$budget;
  1554. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1555. if($info['after_rate']>=$catinfo['rate']){
  1556. //业务主管利率
  1557. $info['rate_status'] =1;
  1558. }
  1559. if ($info['after_rate']>=$catinfo['money_rate']){
  1560. //财务主管利率
  1561. $info['rate_status'] =2;
  1562. }
  1563. if ($info['after_rate']>=$catinfo['lower_rate']){
  1564. //boss利率
  1565. $info['rate_status'] =3;
  1566. }
  1567. $god=[
  1568. "metal_id"=>$bidinfos['metal_id'],
  1569. "weight"=>$bidinfos["good_weight"],
  1570. "demo_fee"=>$bidinfos["demo_fee"],
  1571. "delivery_fee"=>$bidinfos["delivery_fee"],
  1572. "open_fee"=>$bidinfos["open_fee"],
  1573. "packing_fee"=>$bidinfos["pakge_fee"],
  1574. "mark_fee"=>$bidinfos["mark_fee"],
  1575. "nake_fee"=>$bidinfos["nake_fee"],
  1576. "cert_fee"=>$bidinfos["cert_fee"],
  1577. "cost_fee"=>$bidinfos["cost_fee"],
  1578. "num"=>$bidinfoe["num"],
  1579. ];
  1580. $info['gold_price']=0;
  1581. $info['noble_weight']=$bidinfos['good_weight'];
  1582. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1583. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1584. ->find();
  1585. $info['gold_price'] =$gold['price'];
  1586. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1587. }else{
  1588. if($bidinfos['nake_fee']!=0){
  1589. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1590. }else{
  1591. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1592. }
  1593. }
  1594. $info['cost_desc'] =$bidinfos['cost_desc'];
  1595. $info['work_day'] =$bidinfos['work_day'];
  1596. $info['delivery_day'] =$bidinfos['delivery_day'];
  1597. $info['expire_day'] =$bidinfos['expire_day'];
  1598. $info['origin_place'] =$bidinfos['origin_place'];
  1599. $info['origin_addr'] ="";
  1600. if($bidinfos['origin_place']!=''){
  1601. $code = explode(",",$bidinfos['origin_place']);
  1602. $temp=[];
  1603. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1604. $temp['city_code']=isset($code[1])?$code[1]:"";
  1605. $temp['area_code']=isset($code[2])?$code[2]:"";
  1606. $addr= GetAddr(json_encode($temp));
  1607. $info['origin_addr'] = $addr;
  1608. }
  1609. $info['supplierNo'] =$bidinfos['supplierNo'];
  1610. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1611. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1612. $info['pay_way'] =$bidinfos['pay_way'];
  1613. $info['tax'] =$bidinfos['tax'];
  1614. $info['send_way'] =$bidinfos['send_way'];
  1615. $info['metal_id'] =$bidinfos['metal_id'];
  1616. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1617. $info['config'] =$bidinfos['config'];
  1618. $info['other_config'] =$bidinfos['other_config'];
  1619. $info['weight'] =$bidinfos['weight'];
  1620. $info['good_weight'] =$bidinfos['good_weight'];
  1621. $info['is_diff'] =$bidinfos['is_diff'];
  1622. $info['demo_fee'] =$bidinfos['demo_fee'];
  1623. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1624. $info['open_fee'] =$bidinfos['open_fee'];
  1625. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1626. $info['nake_fee'] =$bidinfos['nake_fee'];
  1627. $info['mark_fee'] =$bidinfos['mark_fee'];
  1628. $info['cert_fee'] =$bidinfos['cert_fee'];
  1629. $info['cost_fee'] =$bidinfos['cost_fee'];
  1630. $info['total_fee'] =$bidinfos['total_fee'];
  1631. $info['supply_area'] =$bidinfos['supply_area'];
  1632. $info['remark'] =$bidinfos['remark'];
  1633. $info['is_addrs'] =$consultinfos['is_addrs'];
  1634. $info['is_custom'] =$consultinfos['is_custom'];
  1635. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1636. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1637. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1638. if($info['status']==7){
  1639. $info['lower_price'] =round($lower_price,2);
  1640. }
  1641. //获取议价原因
  1642. if ($info['result_info_id'] != 0) {
  1643. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1644. } else {
  1645. $info['result_info'] = '';
  1646. }
  1647. return app_show(0,"获取成功",$info);
  1648. }
  1649. public function bidlist(){
  1650. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1651. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1652. $where=[['is_del',"=",0]];
  1653. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1654. if ($zxNo !== "") {
  1655. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1656. }
  1657. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1658. if ($infoNo !== "") {
  1659. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1660. }
  1661. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1662. if ($bidNo !== "") {
  1663. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1664. }
  1665. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1666. if ($pgNo !== "") {
  1667. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1668. $where[] = ['infoNo','in',$bidinfo];
  1669. }
  1670. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1671. if ($bargain_status !== "") {
  1672. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1673. $where[] = ['infoNo','in',$bidinfo];
  1674. }
  1675. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1676. if ($projectNo !== "") {
  1677. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1678. ("zxNo");
  1679. $where[] = ['zxNo','in',$zxlist];
  1680. }
  1681. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1682. if($is_own==1){
  1683. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1684. if($token==""){
  1685. return error_show(101,'token不能为空');
  1686. }
  1687. $apply_id =GetUserInfo($token);
  1688. if(empty($apply_id)||$apply_id['code']!=0){
  1689. return error_show(1002,"申请人数据不存在");
  1690. }
  1691. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1692. $where[]=['createrid',"=",$rm];
  1693. }
  1694. $count = Db::name('consult_bids')->where($where)->count();
  1695. $total = ceil($count / $size);
  1696. $page = $page >= $total ? $total : $page;
  1697. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1698. $data=[];
  1699. foreach ($list as $value){
  1700. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1701. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1702. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1703. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1704. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1705. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1706. if($value['brand_id']!=0){
  1707. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1708. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1709. }else{
  1710. $value["brand_name"]="";
  1711. $value["brand_id"]="";
  1712. }
  1713. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1714. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1715. $god=[
  1716. "metal_id"=>$value['metal_id'],
  1717. "weight"=>$value["good_weight"],
  1718. "demo_fee"=>$value["demo_fee"],
  1719. "delivery_fee"=>$value["delivery_fee"],
  1720. "open_fee"=>$value["open_fee"],
  1721. "packing_fee"=>$value["pakge_fee"],
  1722. "mark_fee"=>$value["mark_fee"],
  1723. "nake_fee"=>$value["nake_fee"],
  1724. "cert_fee"=>$value["cert_fee"],
  1725. // "cost_fee"=>$value["cost_fee"],
  1726. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1727. //暂时注掉,搞不清楚原因@吴广广
  1728. "num"=>$bidinfo["num"],
  1729. ];
  1730. $top_cat = made($value['cat_id']);
  1731. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1732. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1733. $price = GoldPrice($god, $budget/100);
  1734. $value['sale_price'] = round($price,2);
  1735. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1736. $value["origin_price"];
  1737. }
  1738. $value['cost_fee'] =$value['origin_cost_fee'];
  1739. $value['specinfo'] = json_decode($value['specinfo'],true);
  1740. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1741. $value['bargain_status']=$bidinfo['bargain_status'];
  1742. //reject驳回原因,status==5表示驳回
  1743. $value['reject']=[];
  1744. if ($value['status'] >=5) {
  1745. $value['reject'] = Db::name('bargain_order')
  1746. ->field('id,remark,status')
  1747. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1748. ->whereIn('status', [3,8,11])->order("id desc")
  1749. ->find();
  1750. }
  1751. //产地
  1752. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1753. if($value['delivery_place']!=""){
  1754. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1755. }
  1756. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1757. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1758. if($value['origin_place']!=""){
  1759. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1760. }
  1761. $value['origin_addr']=GetAddr(json_encode($place));
  1762. // if($value['origin_place']!=''){
  1763. // $code = explode(",",$value['origin_place']);
  1764. // $temp=[];
  1765. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1766. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1767. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1768. // $addr= GetAddr(json_encode($temp));
  1769. // $value['origin_addr'] = $addr;
  1770. // }
  1771. $data[] = $value;
  1772. }
  1773. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1774. }
  1775. public function feedlist(){
  1776. $where=[['is_del',"=",0]];
  1777. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1778. if ($zxNo !== "") {
  1779. $where[] = ['zxNo','=',$zxNo];
  1780. }
  1781. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1782. if ($infoNo !== "") {
  1783. $where[] = ['infoNo','=',$infoNo];
  1784. }
  1785. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1786. if ($bidNo !== "") {
  1787. $where[] = ['bidNo','=',$bidNo];
  1788. }
  1789. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1790. if ($projectNo !== "") {
  1791. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1792. ("zxNo");
  1793. $where[] = ['zxNo','in',$zxlist];
  1794. }
  1795. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1796. if($token==''){
  1797. return error_show(102,"参数token不能为空");
  1798. }
  1799. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1800. if($is_own==1){
  1801. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1802. if($token==""){
  1803. return error_show(101,'token不能为空');
  1804. }
  1805. $apply_id =GetUserInfo($token);
  1806. if(empty($apply_id)||$apply_id['code']!=0){
  1807. return error_show(1002,"申请人数据不存在");
  1808. }
  1809. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1810. $where[]=['createrid',"=",$rm];
  1811. }
  1812. $list =Db::name('consult_bids')->where($where)->select();
  1813. $data=[];
  1814. foreach ($list as $value){
  1815. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1816. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1817. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1818. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1819. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1820. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1821. if($value['brand_id']!=0){
  1822. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1823. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1824. }else{
  1825. $value["brand_name"]="";
  1826. $value["brand_id"]="";
  1827. }
  1828. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1829. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1830. $god=[
  1831. "metal_id"=>$value['metal_id'],
  1832. "weight"=>$value["good_weight"],
  1833. "demo_fee"=>$value["demo_fee"],
  1834. "delivery_fee"=>$value["delivery_fee"],
  1835. "open_fee"=>$value["open_fee"],
  1836. "packing_fee"=>$value["pakge_fee"],
  1837. "mark_fee"=>$value["mark_fee"],
  1838. "nake_fee"=>$value["nake_fee"],
  1839. "cert_fee"=>$value["cert_fee"],
  1840. "cost_fee"=>$value["cost_fee"],
  1841. "num"=>$bidinfo["num"],
  1842. ];
  1843. if ($value['is_gold_price'] == 1 ) {
  1844. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1845. ->find();
  1846. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1847. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1848. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1849. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1850. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1851. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1852. }else{
  1853. if($value["nake_fee"]){
  1854. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1855. }else{
  1856. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1857. (1 - $budget);
  1858. }
  1859. }
  1860. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1861. $value['specinfo'] = json_decode($value['specinfo'],true);
  1862. $value['bargain_status']=$bidinfo['bargain_status'];
  1863. $data[]=$value;
  1864. }
  1865. return app_show(0,"获取成功",$data);
  1866. }
  1867. public function bragain_list(){
  1868. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1869. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1870. $where=[['bo.is_del',"=",0]];
  1871. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1872. if($bidsNo!=""){
  1873. $where[]=["bo.bidsNo","=",$bidsNo];
  1874. }
  1875. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1876. if ($zxNo !== "") {
  1877. $where[] = ['bo.zxNo','=',$zxNo];
  1878. }
  1879. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1880. if ($bargainNo !== "") {
  1881. $where[] = ['bo.bargainNo','=',$bargainNo];
  1882. }
  1883. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1884. if ($status!== "") {
  1885. $where[] = ['bo.status','=',$status];
  1886. }
  1887. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1888. if ($infoNo !== "") {
  1889. $where[] = ['bo.infoNo','=',$infoNo];
  1890. }
  1891. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1892. if ($projectNo !== "") {
  1893. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1894. ("zxNo");
  1895. $where[] = ['bo.zxNo','in',$zxlist];
  1896. }
  1897. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1898. if ($pgNo !== "") {
  1899. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1900. $where[] = ['bo.infoNo','in',$bidinfo];
  1901. }
  1902. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1903. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1904. if($start!=""){
  1905. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1906. }
  1907. if($end!=""){
  1908. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1909. }
  1910. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1911. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1912. $role=$this->checkRole();
  1913. if(!empty($role['write'])){
  1914. $where[]=["bo.createrid","in",$role['write']];
  1915. }
  1916. $count=Db::name("bargain_order")->alias('bo')->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")->where($where)->count();
  1917. $total = ceil($count / $size);
  1918. $page = $page >= $total ? $total : $page;
  1919. $list = Db::name('bargain_order')
  1920. ->alias('bo')
  1921. ->field('bo.*,u.itemid')
  1922. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1923. ->where($where)
  1924. ->page($page, $size)
  1925. ->order('bo.addtime', 'desc')
  1926. ->cursor();
  1927. $data=[];
  1928. foreach ($list as $value){
  1929. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1930. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1931. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1932. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1933. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1934. if($bidinfos['brand_id']!=0){
  1935. $value['brand_id'] = $bidinfos['brand_id'];
  1936. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1937. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1938. }else{
  1939. $value["brand_name"]="";
  1940. $value["brand_id"]="";
  1941. }
  1942. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1943. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1944. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1945. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1946. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1947. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1948. $value['budget'] =$budget;
  1949. $god=[
  1950. "metal_id"=>$bidinfos['metal_id'],
  1951. "weight"=>$bidinfos["good_weight"],
  1952. "demo_fee"=>$bidinfos["demo_fee"],
  1953. "delivery_fee"=>$bidinfos["delivery_fee"],
  1954. "open_fee"=>$bidinfos["open_fee"],
  1955. "packing_fee"=>$bidinfos["pakge_fee"],
  1956. "mark_fee"=>$bidinfos["mark_fee"],
  1957. "nake_fee"=>$bidinfos["nake_fee"],
  1958. "cert_fee"=>$bidinfos["cert_fee"],
  1959. "cost_fee"=>$bidinfos["cost_fee"],
  1960. "num"=>$bidinfoe["num"],
  1961. ];
  1962. // if($bidinfos['is_gold_price']==1){
  1963. // $price = GoldPrice($god, $budget/100);
  1964. // }else{
  1965. // $price = GoodPrice($god, $budget/100);
  1966. // }
  1967. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1968. $value['sale_price'] =round($bidinfos['origin_price'],2);
  1969. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1970. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1971. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  1972. $data[]=$value;
  1973. }
  1974. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1975. }
  1976. public function crontablist(){
  1977. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1978. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1979. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1980. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1981. if ($zxNo !== "") {
  1982. $where[] = ['a.zxNo','=',$zxNo];
  1983. }
  1984. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1985. if ($salesman !== "") {
  1986. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1987. $where[]= ["b.salesman",'like',"%$salesman%"];
  1988. }
  1989. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1990. if ($cpName !== "") {
  1991. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1992. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1993. }
  1994. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1995. if ($khNo !== "") {
  1996. // $where['khNo'] = $khNo;
  1997. $where[]= ["b.khNo",'like',"%$khNo%"];
  1998. }
  1999. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2000. if ($start !="") {
  2001. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2002. $where[]= ["a.addtime",'>=',$start];
  2003. }
  2004. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2005. if($end !=""){
  2006. $where[]= ["a.addtime",'<=',$end];
  2007. }
  2008. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2009. if ($status !== "") {
  2010. $where[]= ["a.status",'=',$status];
  2011. }
  2012. // $role=$this->checkRole();
  2013. // if(!empty($role['platform']) ){
  2014. // $where[]=["b.platform_code","in",$role['platform']];
  2015. // }
  2016. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2017. ->count();
  2018. $total = ceil($count / $size);
  2019. $page = $page >= $total ? $total : $page;
  2020. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2021. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2022. $data=[];
  2023. foreach ($list as $value){
  2024. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2025. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2026. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2027. $value['khname']="";
  2028. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2029. true):[];
  2030. if($value['khNo']!==""){
  2031. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2032. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2033. }
  2034. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2035. ->find();
  2036. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2037. $value['is_feed'] =$consult==false?0:1;
  2038. $value['is_all_feed'] =$consults==false?0:1;
  2039. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2040. $data[]=$value;
  2041. }
  2042. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2043. }
  2044. //复制上面的bidlist方法,只更改排序方式
  2045. public function bidlistCopy()
  2046. {
  2047. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2048. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2049. $where = [['cb.is_del', "=", 0]];
  2050. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2051. if ($zxNo !== "") {
  2052. $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2053. }
  2054. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2055. if ($infoNo !== "") {
  2056. $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2057. }
  2058. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2059. if ($bidNo !== "") {
  2060. $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2061. }
  2062. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2063. if ($pgNo !== "") {
  2064. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2065. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2066. }
  2067. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2068. if ($bargain_status !== "") {
  2069. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2070. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2071. }
  2072. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2073. if ($projectNo !== "") {
  2074. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column
  2075. ("zxNo");
  2076. $where[] = ['cb.zxNo', 'in', $zxlist];
  2077. }
  2078. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2079. if ($is_own == 1) {
  2080. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2081. if ($token == "") {
  2082. return error_show(101, 'token不能为空');
  2083. }
  2084. $apply_id = GetUserInfo($token);
  2085. if (empty($apply_id) || $apply_id['code'] != 0) {
  2086. return error_show(1002, "申请人数据不存在");
  2087. }
  2088. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2089. $where[] = ['cb.createrid', "=", $rm];
  2090. }
  2091. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2092. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2093. $count = Db::name('consult_bids')->alias('cb')->where($where)->count();
  2094. $total = ceil($count / $size);
  2095. $page = $page >= $total ? $total : $page;
  2096. $list = Db::name('consult_bids')
  2097. ->alias('cb')
  2098. ->field('cb.*,u.itemid')
  2099. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2100. ->where($where)
  2101. ->page($page, $size)
  2102. ->order('cb.addtime', 'desc')
  2103. ->cursor();
  2104. $data = [];
  2105. foreach ($list as $value) {
  2106. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2107. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2108. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2109. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2110. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2111. $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2112. if ($value['brand_id'] != 0) {
  2113. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2114. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2115. } else {
  2116. $value["brand_name"] = "";
  2117. $value["brand_id"] = "";
  2118. }
  2119. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2120. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2121. $god = [
  2122. "metal_id" => $value['metal_id'],
  2123. "weight" => $value["good_weight"],
  2124. "demo_fee" => $value["demo_fee"],
  2125. "delivery_fee" => $value["delivery_fee"],
  2126. "open_fee" => $value["open_fee"],
  2127. "packing_fee" => $value["pakge_fee"],
  2128. "mark_fee" => $value["mark_fee"],
  2129. "nake_fee" => $value["nake_fee"],
  2130. "cert_fee" => $value["cert_fee"],
  2131. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2132. "num" => $bidinfo["num"],
  2133. ];
  2134. if ($value['is_gold_price'] == 1) {
  2135. $price = GoldPrice($god, $budget / 100);
  2136. $value['sale_price'] = round($price, 2);
  2137. }
  2138. $value['cost_fee'] = $value['origin_cost_fee'];
  2139. $value['specinfo'] = json_decode($value['specinfo'], true);
  2140. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2141. $value['bargain_status'] = $bidinfo['bargain_status'];
  2142. //reject驳回原因,status==5表示驳回
  2143. $value['reject'] = [];
  2144. if ($value['status'] >= 5) {
  2145. $value['reject'] = Db::name('bargain_order')
  2146. ->field('id,remark,status')
  2147. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2148. ->whereIn('status', [3, 8, 11])->order("id desc")
  2149. ->find();
  2150. }
  2151. //产地
  2152. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2153. if ($value['delivery_place'] != "") {
  2154. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2155. }
  2156. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2157. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2158. if ($value['origin_place'] != "") {
  2159. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2160. }
  2161. $value['origin_addr'] = GetAddr(json_encode($place));
  2162. // if($value['origin_place']!=''){
  2163. // $code = explode(",",$value['origin_place']);
  2164. // $temp=[];
  2165. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2166. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2167. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2168. // $addr= GetAddr(json_encode($temp));
  2169. // $value['origin_addr'] = $addr;
  2170. // }
  2171. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2172. $data[] = $value;
  2173. }
  2174. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2175. }
  2176. }